Got it

Python - Telnet to Huawei routers with script

Latest reply: Mar 16, 2022 02:02:00 1913 3 3 0 0




import telnetlib
import socket
ipfile = "129.9.0.104"
user = "root"
password = "Test1234."
outputfile = ((ipfile)+".output")
f = open(outputfile, 'w')
f.write("")
f.close()

with open(ipfile) as ips:
   all_ips = [x.rstrip() for x in ips] # get all ips in a list and strip newline

for ip in all_ips:

 try:
    tn = telnetlib.Telnet(ip,23,2)
    tn.read_until(b"Username: ")
    tn.write(user.encode('ascii') + b"\n")
    if password:
     tn.read_until(b"Password: ")
     tn.write(password.encode('ascii') + b"\n")
     tn.write(b"screen  0 tem\n")
     tn.write(b"display version\n")      #    print(tn.read_all().decode('ascii'))

          with open(outputfile,"ab") as f:    #write to a fil
       f.write(tn.read_all())
 except socket.timeout:
    print((ip)+" timeout")


For more information about Telnet through Python, you can refer to the following post.
SDN and automation - Python Telnetlib

View more
  • x
  • convention:

Interesting
View more
  • x
  • convention:

Gzüel bir paylaşım Python - Telnet to Huawei routers with script-4761361-1
View more
  • x
  • convention:

DDSN
Admin Created Mar 16, 2022 02:02:00

For more information about Telnet through Python, you can refer to the following post.
SDN and automation - Python Telnetlib

View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.