首页 > 代码库 > Python批量检测连通性
Python批量检测连通性
#!/usr/bin/env python3 #author:zhouxia #date:2016-08-05 import socket def checkip(ipaddr,port): try: sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.settimeout(3) sock.connect((ipaddr,port)) return True except socket.error as e: return False finally: sock.close() if __name__ == ‘__main__‘: file = open("ip_list.txt") checkinfo = open("check_info.txt",‘w+‘) line = file.readline() while line: if line == "": continue iplist = line.split(‘ ‘) ipaddr = iplist[0] port = int(iplist[1]) status = checkip(ipaddr,port) if status == True: info = ‘%s %s is OK‘ % (ipaddr, port)+‘\n‘ checkinfo.write(info) else: info = ‘%s %s is Fail‘ % (ipaddr, port)+‘\n‘ checkinfo.write(info) line = file.readline() file.close()
本文出自 “Dream” 博客,转载请与作者联系!
Python批量检测连通性
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。