Making a Fast Port Scanner

前端 未结 9 731
眼角桃花
眼角桃花 2021-02-03 12:48

So I\'m making a port scanner in python...

import socket
ip = \"External IP\"
s = socket.socket(2, 1) #socket.AF_INET, socket.SOCK_STREAM

def porttry(ip, port):         


        
9条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 13:24

    here is a quick and simple port scanner, it scans 100000 ports in 180 sec:

    import threading
    import socket
    
    target = 'pythonprogramming.net'
    #ip = socket.gethostbyname(target)
    
    def portscan(port):
    
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(0.5)# 
    
        try:
            con = s.connect((target,port))
    
            print('Port :',port,"is open.")
    
            con.close()
        except: 
            pass
    r = 1 
    for x in range(1,100): 
    
        t = threading.Thread(target=portscan,kwargs={'port':r}) 
    
        r += 1     
        t.start() 
    

提交回复
热议问题