本文实例为大家分享了python 3.6.7端口扫描器的具体代码,供大家参考,具体内容如下
环境:python 3.6.7
# -*- coding: utf-8 -*-
import socket
import threading
import argparse
lock = threading.Lock()
openNum = 0
threads = []
def portscan(ip, port):
global openNum
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
lock.acquire()
openNum = openNum + 1
print('[+] %d open' %port)
lock.release()
s.close()
except:
pass
def main():
parse = argparse.ArgumentParser()
parse.add_argument('-H', dest = 'ip', type = str)
args = parse.parse_args()
ip = args.ip
socket.setdefaulttimeout(3)
for port in range(1, 1024):
t = threading.Thread(target = portscan, args = (ip, port))
threads.append(t)
t.start()
for t in threads:
t.join()
print('[*] The host:%s scan is complete!' %(ip))
print('[*] A total of %d open port ' %(openNum))
if __name__ == '__main__':
main()
您可能感兴趣的文章:python nmap实现端口扫描器教程Python3多线程版TCP端口扫描器用Python编写一个高效的端口扫描器的方法使用Python3制作TCP端口扫描器Python实现简易端口扫描器代码实例实例探究Python以并发方式编写高性能端口扫描器的方法使用Python编写简单的端口扫描器的实例分享python编写简单端口扫描器