Python multi-thread port scanning code example, python multi-thread
The code in this article implements multi-threaded port scanning in Python. The specific implementation code is as follows.
# Coding: utf-8import socketimport threadimport timesocket. setdefatimetimeout (3) def socket_port (ip, port): try: if port> = 65535: print (u "port Scan ends! ") S = socket. socket (socket. AF_INET, socket. SOCK_STREAM) # create socket result = s. connect_ex (ip, port) # link port if (result = 0): print ip, u ":", port, u "port Development" s. close () packet T: print (ip, ":", port) print (u "port Scan exception") def IP_port (data): try: ip = "127.0.0.1" t = time. time () for I in range (+ 1): thread. start_new_thread (socket_port, (ip, int (I) # multi-thread scan port time. sleep (0.003) print (u "when the scan port is completed: time _: % s" % (time. time ()-t) failed t Exception as e: print (e) print (ip, I) print (u "Port Scan Exception ") if _ name _ = '_ main _': print u "start to work" # socket_port ("127.0.0.1", 135) IP_port ("127.0.0.1 ")
The result is as follows:
Start work
127.0.0.1: port 135 Development
127.0.0.1: port 445 Development
Time _: 3.00300002098 when the scan port is completed
>>>
Summary
The above is all the content of this article on the Python multi-threaded port scanning code example, I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!