Python 多线程端口扫描软件

Python 多线程端口扫描软件

Python 写的开放式端口扫描.速度比c语言写的慢不少.我想可能是语言问题.

 

import  socket,sys,threading
try :
    hostname
= sys.argv[ 1 ]
    portStart
= int(sys.argv[ 2 ])
    portEnd
= int(sys.argv[ 3 ])
    threadNum
= int(sys.argv[ 4 ])
except :
    
print   """ Python Port Scan Tool 
    Useage: pyScan ip port_Start port_End thread_Number
"""
    sys.exit(
1 )
    

print   " Pytho Port open scan tool by hide1713 "  
print   " scan host: %s from ports %s to %s use %s threads " % (hostname,portStart,portEnd,threadNum)
def  ScanPort(start,end):
    
# print "scan form %d to %d"%(start,end)

    s
= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    
for  port  in  range(start,end):
        
try :
            s.connect((hostname,port))
            
print   " port %d is open " % port
            s.shutdown(
1 )
            
            
# print "scaning port:",port
         except :
            
continue
        
            
socketNum
= int((portEnd - portStart) / threadNum)
end
= portStart
for  n  in  range(threadNum):
    
if  n == threadNum - 1 :
        end
= portEnd
    
else :
        end
+= socketNum
    
# print "Start thread number %d scan port form %d to %d"%(n,portStart,end)
    t = threading.Thread(target =  ScanPort,args = (portStart,end))
    t.start()
    portStart
= end
    
        

 

你可能感兴趣的:(Python 多线程端口扫描软件)