Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telnetlib
- import time
- import os
- #Open telnet connection to devices
- def open_telnet_conn(ip):
- try:
- username = 'jtavares'
- password = '1010522Jr@'
- port = 23
- #Specify the connection timeout in seconds for blocking operations
- connection_timeout = 5
- reading_timeout = 5
- #Loggin into device
- connection = telnetlib.Telnet(ip,port, connection_timeout)
- #Waiting to be asked for a username
- router_output = connection.read_until("username:", reading_timeout)
- #Enter the username
- connection.write(username + "\n")
- time.sleep(1)
- #Waiting to be asked the password
- router_output = connection.read_until("password:", reading_timeout)
- #Enter the password when asked
- connection.write(password + "\n")
- #Sends a command to the routter
- connection.write("terminal length 0\n")
- connection.write("show running 0\n")
- a=connection.read_very_eager()
- print(a)
- #Closing the connection
- connection.close()
- except IOError:
- print ("Input parameter error!")
- open_telnet_conn('10.8.4.100')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement