python简易端口扫描器

默认分类 2016-11-08

Python多线程实现常见端口扫描

import threading 
import sys
import socket
import threading 
import sys

port_list = [21, 22, 23, 25, 80, 135, 137, 139, 445, 1433, 1502, 3306, 3389, 8080 ,9015]
target_ip = sys.argv[1]
#print target_ip
Lock = threading.Lock()

def scan_port(target_ip,target_port):
    #global target
    try:
        s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        s.connect((target_ip,target_port))
        Lock.acquire()  
        print u'port :'+str(target_port)+' is opening'
        Lock.release()
        s.close()
    except Exception,e:
        #with Lock:
        pass

if __name__ == '__main__':
    for port in port_list:
        #scan_port(target_ip,port)
        t=(threading.Thread(target = scan_port,args = (target_ip,port)))
        t.setDaemon(True)
        t.start()
    t.join()

本地测试效果如下:


python菜鸟,练手中......


本文由 sp4rk 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论