#1
|
|||
|
|||
![]()
Just thought I would share theis script Imade to get IOS versions off of Cisco 2900,2950 and 2948 Switches.
The script ask for a few questions then outputs the IOS information into an Excel spread sheet. I know this stuff has been done before, but of couse there are many way to do the same thing, this is one way that worked well for me! # $language = "VBScript" # $interface = "1.0" '================================================================= 'LANG :VBScript 'NAME ![]() 'VERSION : 1 'Date ![]() 'Description :Gets IOS Versions off of Cisco 2950 and 2900 And 2948 Switches ' Using the SecureCRT Program scripting Function and VBScript. ' The script reads IP address from a file, Pings each address ' and Connects to each switch via the SecureCRT and places ' the IOS version information into a text file called ' C:\CRT.Log '================================================================== 'VARIABLES Dim FSO, Shell, Windir, Runservice, oFile, oFile1 Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set FSO = CreateObject("scripting.filesystemobject") Set Shell = CreateObject("WScript.Shell") Set objDictionary = CreateObject("Scripting.Dictionary") Set objSc = crt.Screen Set objD = crt.Dialog Set objSe = crt.Session Set objW = crt.Window strExcelPath = "C:\" strExcelPath = strExcelPath & "Switch audit.xls" Set objExcel = CreateObject("Excel.Application") objExcel.Workbooks.Add Sheet = Sheet + 1 K=2 Set objSheet = objExcel.Worksheets.Add objSheet.Name = "Switches" objSheet.Activate objExcel.Visible = True objSheet.Cells(1, 1).Value = "System IP" objSheet.Cells(1, 2).Value = "Hostname" objSheet.Cells(1, 3).Value = "System Model" objSheet.Cells(1, 4).Value = "IOS Version" objsc.Synchronous = True LogFile = InputBox("Enter file name you want to save the Log created by the sessions"&Chr(13)&Chr(13)&_ "Enter full path to file","Log File Name","C:\CRTLog.Log") SwitchIP = InputBox("Enter file name you want to save the Log created by the sessions"&Chr(13)&Chr(13)&_ "Enter full path to file","Log File Name","C:\SwitchIP.txt") Set SwitchIP = FSO.opentextfile(SwitchIP, ForReading, False) Password = objD.Prompt("Enter password To Get into Switch"&Chr(13)&Chr(13)&_ "Password must be the same for all Switches!","Initial Password",0,True) While Not SwitchIP.atEndOfStream IP = SwitchIP.Readline() ' connect To host On port 23 (the default telnet port) On Error Resume Next objse.Connect "/TELNET "&IP&" 23" SubNet = Split(IP,".") SubnetZeroadded = Right("0" & "0" & Subnet(2),3) If ( objse.connected ) Then objse.logfilename = LogFile objse.Log(True),True objSc.WaitForString "assword:" objSc.Send Password & vbCr objsc.WaitForString">",1 SelectRow1 = objSc.CurrentRow Hostname = objSc.Get(SelectRow1, 1, SelectRow1, 12 ) 'objD.Messagebox "Wrongstr st To " & wrongstr If InStr(HostName,"50") Or Instr(HostName,"00") Then objsc.WaitForString">",1 objsc.Send "sho ver | include IOS" & vbCr objsc.WaitForString">",3 SelectRow = objSc.CurrentRow - 1 IOSline = objSc.Get(SelectRow, 1, SelectRow, 132 ) ' objD.Messagebox IOSline IOSVER = Split(IOSline," ") objSheet.Cells(k, 1).Value = IP objSheet.Cells(k, 2).Value = Hostname objSheet.Cells(k, 3).Value = IOSVER(4) objSheet.Cells(k, 4).Value = IOSVER(6) k = k + 1 'objD.Messagebox IOSline 'objse.Log(False) objSc.Synchronous = False objSE.Disconnect Else objsc.WaitForString">",1 objsc.Send "show version" & vbCr objsc.WaitForString">",1 SelectRow = objSc.CurrentRow - 22 'objD.Messagebox objSC.Get(SelectRow, objSc.Currentcolumn -objSc.columns, objSc.CurrentRow, objSc.Currentcolumn +132) IOSline = objSc.Get(SelectRow, 1, SelectRow, 132 ) 'objD.Messagebox IOSline IOSVER = Split(IOSline," ") objSheet.Cells(k, 1).Value = IP objSheet.Cells(k, 2).Value = Hostname objSheet.Cells(k, 3).Value = IOSVER(0) objSheet.Cells(k, 4).Value = IOSVER(3)& IOSVER(4) 'objse.Log(False) objSc.Synchronous = False objSE.Disconnect k = k + 1 End If Else Set Tempfile = FSO.OpenTextFile("C:\NoConnect.txt",ForAppending, True) TempFile.writeline "Could Not Connect to " & IP TempFile.Close() End If Wend objSheet.Range("A1:AJ1").Font.Bold = True objSheet.Select objSheet.Range("A2").Select objExcel.ActiveWindow.FreezePanes = True objExcel.Columns("A:AJ").EntireColumn.AutoFit ' Save the spreadsheet and close the workbook. objExcel.ActiveWorkbook.SaveAs strExcelPath 'objExcel.ActiveWorkbook.Close ' Quit Excel. 'objExcel.Application.Quit Response = MsgBox("Would you like to see the log file?",vbYesNo,"See Log?") If Response = "6" Then Shell.Run "Notepad " & LogFile,8 End If Response2 = MsgBox("Switches the script could not connect to?",vbYesNo,"No Connect file") If Response2 = "6" Then Shell.Run "Notepad C:\NoConnect.txt",8 End If |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|