您好,登錄后才能下訂單哦!
本文實例為大家分享了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()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。