#!/usr/bin/env python3#author:zhouxia#date:2016-08-05import socketdef 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 ' &nbsP; checkinfo.write (Info) Line = file.readline () file.close ()
This article from "Dream" blog, reproduced please contact the author!
Python Bulk Detection connectivity