Pyhton Scan Port Script code
#-*-Coding:utf8-*-#!/usr/bin/python# Program: Port scan import socket, time, Threadsocket.setdefaulttimeout (3) def Soc Ket_port (Ip,port): "" "Enter IP and port number, scan to determine if port is open" "Try:if port>=65535:print U ' port scan end ' S=socket.socket (socket.af_inet, socket. Sock_stream) result=s.connect_ex ((ip,port)) if Result==0:lock.acquire () print ip,u ': ', Port,u ' Port Open ' lock.release () s.close () except:print u ' Port scan exception ' def ip_scan (IP): ' "" Input IP , scan IP 0-65534 port case "" "Try:print U ' start scan%s '% IP start_time=time.time () for I in range (0,65534) : Thread.start_new_thread (Socket_port, (Ip,int (i))) Print U ' Scan port complete, total time:%.2f '% (Time.time ()-start_time) Raw_input ("Press Enter to Exit") except:print u ' scan IP error ' if __name__== ' __main__ ': url=raw_input (' input The IP want to scan:\n ') Lock=thread.allocate_lock () Ip_scan (URL)