python扫面端口
Posted kmnskd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python扫面端口相关的知识,希望对你有一定的参考价值。
利用TCP连接创建一个socket扫描port
上代码:
#TCP import socket from threading import Thread def get_port(open_port,host,ports): while True: if ports: port = ports.pop(0) c = socket.socket(socket.AF_INET,socket.SOCK_STREAM) c.settimeout(0.5) try: c.connect((host,port)) except socket.timeout as e: print(‘[-]%d‘ % port) del c else: print(‘[+]%d‘ % port) c.send(‘1‘.encode()) portocol = c.recv(1024).decode() open_port[port] = portocol c.close() del c else: break def main(): host = "192.168.1.33" open_port = {} ports = list(range(1,65535)) t_list = [] for var in range(100): t_list.append(Thread(target=get_port,args=(open_port,host,ports,))) for t in t_list: t.start() for t in t_list: t.join() get_port(open_port,host,ports) print(open_port) if __name__ == ‘__main__‘: main()
以上是关于python扫面端口的主要内容,如果未能解决你的问题,请参考以下文章