1.将服务器ip和端口导入ip.txt文件。格式如下:
cat ip.txt
192.168.1.1 80
192.168.1.2 8080
编写python脚本:如下:
#!/bin/env python
# -*- encoding: utf-8 -*-
import os
import re
import sys
import telnetlib
file=open('ip.txt','r+')
for i in file.readlines():
ii=i.split(" ")
ip=ii[-2]
port=ii[-1][:-1]
# print(ip,port)
try:
telnetlib.Telnet(ip,port, timeout=2)
print("{} {}成功".format(ip,port))
# pass
except:
print("{} {}失败".format(ip,port))
file.close()
文章完