发布时间:2019-08-28 09:11:06编辑:auto阅读(2074)
#!/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()
上一篇: Python带权重随机数的简单实现
下一篇: python中查看变量内存地址的方法
51316
50768
41362
38169
32651
29541
28385
23259
23229
21554
1629°
2363°
1966°
1910°
2239°
1947°
2640°
4425°
4266°
3037°