Simple multi-threaded port scanning Tool
You can receive an IP address as a parameter, and if you do not, the port of the native is scanned by default
1 #!/usr/bin/python2 3 ImportSocket4 Import Time5 ImportArgparse6 ImportThreading7 8 defarg_process ():9Argparser=argparse. Argumentparser (description="Port Scaner")TenArgparser.add_argument ('- I.','--ip', action='Store', dest='IP', default='localhost') Oneargs=Argparser.parse_args () Aip=Args.ip - returnIP - the defScan (ip,port): - ifport>=65535: - Pass - Else: +Addr=(Ip,port) -sock=Socket.socket (Socket.af_inet,socket. SOCK_STREAM) + Try: Astatus=sock.connect_ex (addr) at ifstatus==0: - Print "%d opened"%Port - - except: - Pass - finally: in sock.close () - to defMain (start,stop): +ip=arg_process () - forPortinchRange (start,stop): the Scan (ip,port) * $ Panax Notoginseng if __name__=='__main__': -t1=time.time () thethreads=[] + forIinchRange (20): AT=threading. Thread (target=main,args= (3277*i,3277* (i+1))) the threads.append (t) + forTinchThreads: - T.setdaemon (True) $ T.start () $ T.join () -T2=time.time () -delta=t2-T1 the Print "It spend%d seconds"%delta
Port Scan Tool