Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-31-2004, 11:38 AM
wasodg2 wasodg2 is offline
Registered User
 
Join Date: Dec 2004
Location: Spokane, WAshington
Posts: 16
Red face Share Switch Version Script

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 ave Gest
'VERSION : 1
'Date ec 22, 2004
'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
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:09 AM.