A gadget that uses Python to scan a fixed port to receive parameters: Start IP, terminate IP, target port. and test success, so in this record, Daniel do not spray.
#coding =utf-8 Import Socket import time import sys def portscanner (ip,port): Server = (ip,port) SOCKFD = Socket.s Ocket (Socket.af_inet,socket. SOCK_STREAM) Sockfd.settimeout (0.1) ret = SOCKFD.CONNECT_EX (server) #返回0则成功 if not ret:sockfd.close ( ) print '%s:%s is opened ... '% (ip,port) else:sockfd.close () pass return ' Def ip2num (i
P): LP = [INT (x) for x in Ip.split ('. ')] Return lp[0] << 24 | LP[1] << 16 | LP[2] << 8 |lp[3] def num2ip (num): IP = [', ', ', ', '] ip[3] = (num & 0xff) ip[2] = (num & 0xff0 0) >> 8 ip[1] = (num & 0xff0000) >> ip[0] = (num & 0xff000000) >> return '%s.% s.%s.%s '% (ip[0],ip[1],ip[2],ip[3]) def iprange (ip1,ip2): Num1 = Ip2num (ip1) num2 = Ip2num (IP2) tmp = num2- NUM1 if tmp < 0:return None Else:return num1,num2,tmp if __name__ = ' __main__ ': print ' Start time:%s '% tIme.ctime (Time.time ()) If Len (SYS.ARGV) < 4:print ' Usage:scanner01 startip endip Port ' Sys.exit () res = () StartIP = sys.argv[1] EndIP = sys.argv[2] Port = Int (sys.argv[3)) res = IPRange (startip,endip If not Res:print ' endip must to bigger than Startone ' Sys.exit () elif res[2] = = 0:port
Scanner (Startip,port) else:for x in xrange (int (res[2)) +1: Startipnum = Ip2num (StartIP) Startipnum = startipnum + x portscanner (Num2ip (startipnum), port) print ' End time:%s '% Time.ctime (Tim
E.time ())
Test the 3389-port opening of a network segment ... The results are as follows: