python 3.6.7实现端口扫描器
本文实例为大家分享了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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持安科网。
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16