【工作常用代码集】批量Telnet远端端口

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/

__author__ = 'gnuhpc'

import telnetlib,socket

IP={}

def parseTel(line):
    parseArray = line.split()
    IP[parseArray[0]]=parseArray[1]

with open("tel.lst") as f:
    for line in f:
        parseTel(line)

for (ip,port) in  IP.items():
    try:
        tn = telnetlib.Telnet(ip,port,1)
        tn.close()
    except socket.error, why:
        print ip,port,why
posted @ 2014-07-04 20:44  gnuhpc  阅读(2915)  评论(0编辑  收藏  举报