Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2.1
- import telnetlib
- router_ip = "192.168.122.169"
- username = "admin"
- password = "cisco"
- tn = telnetlib.Telnet(router_ip)
- tn.read_until("Username: ")
- tn.write(username + "\n")
- tn.read_until("Password: ")
- tn.write(password + "\n")
- tn.write("terminal length 0\n")
- def getConfigFromRouter(config_type):
- tn.write("show " + config_type + "\n")
- tn.read_until("version")
- return set(("version" + tn.expect([".+#$"])[2]).splitlines())
- startup_cfg = getConfigFromRouter("startup-config")
- running_cfg = getConfigFromRouter("running-config")
- diff = running_cfg.difference(startup_cfg)
- if(len(diff)>0):
- print("startup-config modified lines:")
- for l in diff:
- print l
- print("\nWas before:")
- for l in startup_cfg.difference(running_cfg):
- print l
- else:
- print("startup-config and running-config are the same.")
- tn.write("exit\n")
- tn.read_all()
- 2.2**************
- import telnetlib
- router_ip = "192.168.122.169" # Cisco IOSv15.6(1)T-1 router IP
- username = "admin" # telnet login
- password = "cisco" # telnet password
- cfg_filename = "old_cfg.txt" # old config file
- tn = telnetlib.Telnet(router_ip) # Connecting to a host (router)
- tn.read_until("Username: ") # Reading telnet output until there is Username text
- tn.write(username + "\n") # Sending username and new line symbol (as enter key)
- tn.read_until("Password: ") # Reading telnet output until there is Password text
- tn.write(password + "\n") # Sending pass and new line symbol (as enter key)
- tn.write("terminal length 0\n") # (to not to pause terminal output)
- def getConfigFromRouter(config_type): # function for reading config from the router
- tn.write("show " + config_type + "\n") # sending show startup-config or running-config
- tn.read_until("version") # skipping text until version is displayed
- return set(("version" + tn.expect([".+#$"])[2]).splitlines()[:-1])
- def compareConfigs(file_config, running):
- diff = file_config.difference(running) # comparing 2 configs
- if(len(diff)>0): # if theres is a diffrence
- print("running-config modified lines:")
- for l in diff: # looping and printing diff
- print l
- print("\nLines in " + cfg_filename + ":")
- for l in running.difference(file_config):
- print l
- else: # if theres no diff printing that theres none
- print("config from file (" + cfg_filename + ") and running-config are the same.")
- running_cfg = getConfigFromRouter("running-config")
- file_cfg = set(open(cfg_filename, "r").read().splitlines()) # opening and reading whole file converting it to lines and to then to set
- compareConfigs(file_cfg, running_cfg)
- tn.write("exit\n") #sending exit to log out out of the router
- tn.read_all()
- 3**************************************************************************
- version 15.6
- service timestamps debug datetime msec
- service timestamps log datetime msec
- no service password-encryption
- !
- hostname R1
- !
- boot-start-marker
- boot-end-marker
- !
- !
- !
- no aaa new-model
- ethernet lmi ce
- !
- !
- !
- mmi polling-interval 60
- no mmi auto-configure
- no mmi pvc
- mmi snmp-timeout 180
- !
- !
- !
- !
- !
- no ip icmp rate-limit unreachable
- !
- !
- !
- !
- !
- !
- no ip domain lookup
- ip domain name cisco.com
- ip cef
- no ipv6 cef
- !
- multilink bundle-name authenticated
- !
- !
- !
- !
- username admin privilege 15 password 0 cisco
- !
- redundancy
- !
- no cdp log mismatch duplex
- !
- ip tcp synwait-time 5
- !
- !
- !
- !
- !
- !
- !
- !
- !
- !
- !
- !
- !
- interface GigabitEthernet0/0
- ip address dhcp
- duplex auto
- speed auto
- media-type rj45
- !
- interface GigabitEthernet0/1
- no ip address
- shutdown
- duplex auto
- speed auto
- media-type rj45
- !
- interface GigabitEthernet0/2
- no ip address
- shutdown
- duplex auto
- speed auto
- media-type rj45
- !
- interface GigabitEthernet0/3
- no ip address
- shutdown
- duplex auto
- speed auto
- media-type rj45
- !
- ip forward-protocol nd
- !
- !
- no ip http server
- no ip http secure-server
- ip ssh version 2
- !
- !
- !
- !
- control-plane
- !
- banner exec ^C
- **************************************************************************
- * IOSv is strictly limited to use for evaluation, demonstration and IOS *
- * education. IOSv is provided as-is and is not supported by Cisco's *
- * Technical Advisory Center. Any use or disclosure, in whole or in part, *
- * of the IOSv Software or Documentation to any third party for any *
- * purposes is expressly prohibited except as otherwise authorized by *
- * Cisco in writing. *
- **************************************************************************^C
- banner incoming ^C
- **************************************************************************
- * IOSv is strictly limited to use for evaluation, demonstration and IOS *
- * education. IOSv is provided as-is and is not supported by Cisco's *
- * Technical Advisory Center. Any use or disclosure, in whole or in part, *
- * of the IOSv Software or Documentation to any third party for any *
- * purposes is expressly prohibited except as otherwise authorized by *
- * Cisco in writing. *
- **************************************************************************^C
- banner login ^C
- **************************************************************************
- * IOSv is strictly limited to use for evaluation, demonstration and IOS *
- * education. IOSv is provided as-is and is not supported by Cisco's *
- * Technical Advisory Center. Any use or disclosure, in whole or in part, *
- * of the IOSv Software or Documentation to any third party for any *
- * purposes is expressly prohibited except as otherwise authorized by *
- * Cisco in writing. *
- **************************************************************************^C
- !
- line con 0
- exec-timeout 0 0
- privilege level 15
- logging synchronous
- line aux 0
- exec-timeout 0 0
- privilege level 15
- logging synchronous
- line vty 0 3
- login
- transport input none
- line vty 4
- login local
- transport input all
- !
- no scheduler allocate
- !
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement