python脚本实现telnet批量登录

2020/03 13 15:03

Python脚本如下:

 

import sys
import telnetlib
#import getpass
ip='192.168.'
bip=0
cip='1'
while bip<=254:
        try:
                HOST = ip + str(bip) + '.' + cip
                print ("ipis:%s"%HOST)
                user = 'msfadmin'
                password = 'msfadmin'
                tn = telnetlib.Telnet(HOST)
                tn.read_until("login:")
                tn.write(user+"\n")
                if password:
                        tn.read_until("Password:")
                        tn.write(password+"\n")
                tn.write("cat /a.txt\n")
                tn.write("exit\n")

                print (tn.read_all())
                bip=int(bip)
                bip+=1
        except:
                print('waring!! ip is:%s'% HOST)
                bip=int(bip)
                bip+=1
                continue

1 Comment

  1. #1
    admin

    admin

    2years ago -@

    测试

  2. 发表回复

    欢迎回来 (打开)

    (必填)