Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import telnetlib
- from my_ccie_routers import PE1, PE2, P1, P2, P3, P4
- def open_telnet_conn(ip):
- global username
- global password
- telnet_port = 23
- telnet_timout = 5
- read_timout = 5
- #Logging into device
- connection = telnetlib.Telnet(ip, telnet_port, telnet_timout)
- output = connection.read_until("Username:", read_timout)
- connection.write(username + "\n")
- output = connection.read_until("Password:", read_timout)
- connection.write(password + "\n")
- time.sleep(1)
- # output = connection.read_until(">", read_timout)
- # connection.write('enable' + "\n")
- # time.sleep(1)
- # output = connection.read_until("Password:", read_timout)
- # connection.write(password + "\n")
- # time.sleep(1)
- #Setting terminal length for entire output - no pagination
- connection.write("terminal length 0\n")
- #time.sleep(1)
- #Entering global config mode
- connection.write("\n")
- connection.write("configure terminal\n")
- time.sleep(1)
- global router_hostname
- print "Python successfully entered the configuration mode of " + ' ' + router_hostname
- print "=================================================================================="
- connection.write("\n")
- global Configurations_to_be_pushed
- connection.write(Configurations_to_be_pushed)
- time.sleep(1)
- #to see the command line of the routers while configuring them
- output = connection.read_very_eager()
- print output
- username = 'ccie'
- password = 'ccie'
- routers = [P1, P2, P3, P4, PE1, PE2]
- for router in routers:
- router_ip = router['ip']
- router_hostname = router['hostname']
- Configurations_to_be_pushed = 'username python password python'
- open_telnet_conn(router_ip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement