#1
|
|||
|
|||
Script to download and compare configs
Hi all,
Is there a script to download configs of multiple routers/switch and compare for config differences? I am auditing hundreds of devices that are missing some commands and comparing them against known good configuration devices and documenting which commands are missing. There has to be an easier way to do this than comparing each and everyone with different similar devices. ![]() Thanks Damon |
#2
|
|||
|
|||
Hi Damon,
We don't have an example that does what you are asking, but it seems like it would be possible to modify the example at the following location to meet your needs: https://forums.vandyke.com/showthrea...7294#post37294Are you able to create your own solution using the example as a beginning point? |
#3
|
|||
|
|||
Quote:
![]() |
#4
|
||||
|
||||
Hi Damon,
I also had a similar issue with hundreds of Cisco switches/routers to backup their config. So I made this script which uses a single "devices.txt" file where I store IPaddress/hostname/username/password/enable password separated by ";" on each line. It then reads it , connects to each one, saves configs in form of "hostname".txt files -devices.txt file is located on same folder as the script -I also connect first to a Linux server before connecting to devices. Hope it helps out and let me know if you have some other improvement ideas ![]() Code:
#$language = "VBScript" #$interface = "1.0" ' Test Script to log in via SSH/telnet and enters in privileged mode ' IF enable password is not set or you connect with TACACS/Radius directly in privileged mode, ' then comment the lines after Loop until the next comment section ' This version uses only one "devices.txt" file to store IP Address;hostname;username;password;enable password Dim g_objTab Set g_objTab = crt.GetScriptTab Sub Main CRT.Screen.synchronous = True If crt.Session.Logging Then ' Turn off session logging before setting up our script's crt.Session.Log False ' logging... if needed End If Dim fso ' Declaring filesystemobject Dim fil ' Declaring file containing devices Dim vWaitFors ' Array to determine if RSA key is known, also to determine if SSH or Telnet is enabled vWaitFors = Array("(yes/no)?",_ "port 22: Connection refused",_ "assword:") Const DEVICE_FILE_PATH = ".\devices.txt" ' Path to devices list (can be modified, now it points to same folder where script is located) Set fso = CreateObject("Scripting.FileSystemObject") Set fil = fso.OpenTextFile(DEVICE_FILE_PATH) ' Open devices file While Not fil.AtEndOfStream ' Read devices.txt. Until not EOF do : line = fil.ReadLine ' Read line by line Device = Split(line, ";")(0) ' Device's IP address hostname = Split(line,";")(1) ' hostname - for easy human read username = Split(line,";")(2) ' username to connect to device pass = Split(line,";")(3) ' password for username pass2 = Split(line,";")(4) ' password to enter privileged mode if needed crt.Screen.Send "ssh " + username + "@" + Device & chr(13) ' First try to connect via SSH to device Do Dim nResult nResult = crt.Screen.WaitForStrings(vWaitFors) Select Case nResult ' Now determine if RSA key has to be added or not in SSH case or try via Telnet Case 1 ' RSA key for /.ssh/known_hosts must be added crt.Screen.Send "yes" & chr(13) ' so send and "yes" crt.Screen.WaitForString "assword:" ' then wait for password prompt crt.Screen.Send pass & chr(13) ' and send pass Case 2 ' SSH not enabled on device, then go for telnet crt.Screen.Send "telnet " + Device & chr(13) crt.Screen.WaitForString "sername:" crt.Screen.Send username & chr(13) crt.Screen.WaitForString "assword:" crt.Screen.Send pass & chr(13) Case 3 ' RSA key already learned crt.Screen.Send pass & chr(13) ' just send pass from credentials file End Select Exit Do Loop crt.Screen.WaitForString ">" ' Waits for prompt crt.Screen.Send "enable" & chr(13) ' Enable crt.Screen.WaitForString "assword:" crt.Screen.Send pass2 & chr(13) ' sends enable pass crt.Screen.WaitForString "#" ' waits for privileged mode prompt ' From now on, just put whatever commands you need for your device ' use crt.Screen.Send "command" & chr(13) --- to send what you want, chr(13) stands for ENTER key ' use after each command an crt.Screen.WaitForString "#" -- to wait for prompt after command's output ' Or even better just use SendExpect "command", "prompt" --- see below function SendExpect "terminal length 0", hostname + "#" crt.Session.logFileName = ".\" + hostname + ".txt" crt.Session.Log True SendExpect "show running-config", hostname + "#" crt.Session.Log False ' Commands sent/received output ends here. Next is disconnecting from device SendExpect "exit", "]$ " ' Closes connection & Waits for Terminal Server prompt and is ready for next device Wend fil.Close ' Close devices file End Sub ' THE END OF THE UNIVERSE AS YOU KNEW IT:) Function SendExpect(szSend, szExpect) ' Made this to replace the Screen.Send/Screen.WaitForString pairs ' Returns true if the text in 'szSend' was successfully sent and ' the text in 'szExpect' was successfully found as a result. ' If we're not connected, we can't possibly return true, or even send/recv text if g_objTab.Session.Connected <> True then exit function g_objTab.Screen.Send szSend & vbcr g_objTab.Screen.WaitForString szExpect SendExpect = True End Function |
#5
|
|||
|
|||
Script
Hello, i have a project in which i have to make a script to download configs of multiple routers/switch and compare for config differences , so actually i saw your script and i don't know how to make it work, can you help me please !
|
![]() |
Tags |
cisco , router , scripting , switch |
Thread Tools | |
Display Modes | Rate This Thread |
|
|