1、脚本
#!/usr/bin/env python
import os
import sys
import socket
import msvcrt
b = sys.platform
arr=[]
if ‘win*‘ == b:
config = sys.path[0] + ‘\config.txt‘
else:
config = sys.path[0] + ‘/config.txt‘
file = open(config,"r")
for line in file.readlines():
if line.startswith("#"):
continue
else:
arr.append((line.replace(‘\n‘,‘‘).split(‘ ‘)))
file.close()
for arra in arr:
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sk.settimeout(1)
ip = (str(arra[0]),int(arra[1]))
try:
sk.connect(ip)
print(arra[0] + ‘的端口‘ + arra[1] + ‘通‘)
except Exception :
print(arra[0] + ‘的端口‘ + arra[1] + ‘不通‘ )
sk.close()
msvcrt.getch()
2 配置文件:
#在下方输入服务器的IP或者域名,然后输入空格在加一个端口
#例如:www.xxx.com 80 10.110.110.110 100
www.baidu.com 443
10.11.21.51 110
10.11.29.32 54
10.11.21.51 80
120.2.1.3 569
原文:http://blog.51cto.com/xiaoyuanzheng/2162348