Read the Python stunt today: Using Python as a top hacker, the first chapter uses a small example of Python's basic syntax and statements. The main learning contents are: 1. Install a third-party library. 2. Variables, strings, lists, dictionaries. 3. Programming the network. 4. Conditional selection statement and for loop. 5. Exception handling. 6. function. 7. File input/output. 8. SYS module and OS module. Put the last code here and make a note.
ImportSocketImportOSImportSysport= 21Banner="freefloat FTP Server"portlist= [21,22,80,110]portopen=trueservices= {'FTP': 21,'SSH': 22,'SMTP': 25,'http': 80}defRetbanner (ip,port):Try: Socket.setdefaulttimeout (2) s=Socket.socket () s.connect ((ip,port)) banner= S.RECV (1024) returnBannerexcept: return defCheckvulns (Banner,filename): F= open (filename,'R') forLineinchf.readlines ():ifLine.strip ('\ n')inchBanner:Print '[+] Server is vulnerable:'+ Banner.strip ('\ n')defMain ():ifLen (sys.argv) = = 2: FileName= Sys.argv[1] if notos.path.isfile (filename):Print '[-] '+filename +'does not exist.'exit (0)if notos.access (filename, os. R_OK):Print '[-] '+filename +'access denied.'exit (0)Else: Print '[-] Usage:'+ str (sys.argv[0]) +'<vuln filename>'exit (0) Portlist= [21,22,25,80,110,443] forXinchRange (147,150): IP='192.168.95.'+str (x) forPortinchPortlist:banner=Retbanner (Ip,port)ifBanner:Print '[+] '+ IP +': '+Banner Checkvulns (banner, filename)if __name__=='__main__': Main ()
Learn the basic Python statement by writing a simple vulnerability scanner