国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python 實現端口掃描工具

瀏覽:5日期:2022-07-01 18:10:36

# 簡單的端口掃描工具# 作者: Charles# 公眾號: Charles的皮卡丘import timeimport socketimport threading# 判斷是否為正確的IP地址。def isIP(ip): ip_addr = ip.split(’.’) if len(ip_addr) != 4: return False for ipnum in ip_addr: if not (0 <= int(ipnum) < 255): return False else: return True# 端口掃描工具class scanThread(threading.Thread): def __init__(self, ip, port_min=0, port_max=65535): # 初始化。 threading.Thread.__init__(self) self.port_max = port_max self.port_min = port_min self.ip = ip # assert isinstance(int,self.port_min) and isinstance(int,self.port_max) # 重寫run def run(self): return self.__checker() # 檢測 def __checker(self): for port in range(self.port_min,self.port_max): self.__connect(port) # 連接 def __connect(self,port): socket.setdefaulttimeout(1) self.sock = socket.socket() try: start_time = time.time() self.sock.connect((self.ip,port)) end_time = time.time() connect_time = int(start_time - end_time) info = ’Find --> [IP]: %s, [PORT]: %s, [Connect Time]: %d’ % (self.ip, port, connect_time) print(info) self.__save(info) self.sock.close() except: # print(’出錯誤了’) self.sock.close() def __save(self,info): try: with open(’results.txt’, ’a’) as f: f.write(info + ’n’) except: print(’寫文件出現了問題’) time.sleep(0.1)if __name__ == ’__main__’: # 輸入IP地址。 ip = input(’Input IP(example <xxx.xxx.xxx.xxx>):n’) print(isIP(ip)) while not isIP(ip): ip = input(’請輸入正確的IP地址:n’) # 輸入最小端口、 port_min = input(’需要掃描的最小端口為:’) while not (0 <= int(port_min) < 65535): port_min = input(’請輸入正確的需要掃描的最小端口:’) port_max = input(’需要掃描的最大端口為(65535):’) while not (0 <= int(port_min) < int(port_max) < 65535): port_min = input(’請輸入正確的需要掃描的最大端口(65535):’) num = 8 port_max = int(port_max) port_min = int(port_min) interval = (port_max - port_min) // num for i in range(interval): scanThread(ip, i * num, (i + 1) * num).start()

以上就是python 實現端口掃描工具的詳細內容,更多關于python 端口掃描工具的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 五家渠市| 和平县| 临城县| 都安| 吉林省| 深州市| 延安市| 海盐县| 鄱阳县| 道孚县| 临清市| 上杭县| 浮梁县| 磐安县| 湾仔区| 云安县| 荥经县| 中西区| 泗水县| 甘肃省| 延庆县| 抚远县| 崇州市| 洛扎县| 万盛区| 玉林市| 攀枝花市| 荔浦县| 抚州市| 辽阳市| 呼伦贝尔市| 色达县| 资阳市| 文水县| 云安县| 大同县| 济阳县| 资源县| 卓资县| 宁陵县| 景谷|