#1
|
|||
|
|||
problem combining command strings
Code:
'For i=0 to narray_count current_interface = sinterface(0,5) command = "show interface " & current_interface & " | include address" & chr(13) msgbox command crt.Screen.Send command crt.Screen.WaitForString szStartString But no matter how I try to do it, without fail... it always executes the command "show interface". It tends to show the first interface, then the command prompt is displayed with the remainder of the original command... e.g.--> some sensitive info has been redacted Quote:
Code:
Language="VBScript" Interface="1.0" Sub Main() Dim objTab Dim szStartString, szEndingString, szResult, icount Dim sversion, simage_file, smodel, sinterface(7,200) crt.Screen.Synchronous = True Set objTab = crt.GetScriptTab If Not objTab.session.connected then MsgBox "Not Connected. Please connect before running this script." exit sub end if 'determine prompt value szStartString = "hostname>" szEndingString = "hostname>" more_prompt = "--More--" 'exit sub Dim n_string_start, n_string_end 'pull out the OS version crt.Screen.Send "show version | include Cisco IOS Software" crt.Screen.Send chr(13) szResult = objTab.Screen.ReadString(szEndingString) n_string_start = instr(1,szResult, "Version")+8 n_string_end = instr(n_string_start, szResult, ", ") sverion = mid(szResult, n_string_start, n_string_end - n_string_start) 'pull out the image file name crt.Screen.Send "show version | include flash:/" crt.Screen.Send chr(13) szResult = objTab.Screen.ReadString(szEndingString) n_string_start = instrrev(szResult, chr(47))+1 n_string_end = instrrev(szResult, chr(34)) simage_file = mid(szResult, n_string_start, n_string_end - n_string_start) 'pull out Model #, long version crt.Screen.Send "show version | include Model number" crt.Screen.Send chr(13) szResult = objTab.Screen.ReadString(szEndingString) n_string_start = instrrev(szResult,": ")+2 n_string_end = instrrev(szResult, chr(13)) smodel = mid(szResult, n_string_start,n_string_end - n_string_start) 'pull out interface names and IP address data crt.Screen.Send "show ip interface brief" crt.Screen.Send chr(13) szResult = readfull(more_prompt,szStartString) n_string_start = instr(1, szResult, chr(13))+1 narray_count = 0 do while icount < len(szResult)-1 n_string_start = instr(n_string_start, szResult, chr(13))+1 n_string_end = instr(n_string_start, szResult, " ") sinterface(0,narray_count) = mid(szResult, n_string_start,n_string_end - n_string_start) do find_IP = mid (szResult, n_string_end, 1) if (find_IP=" ") then n_string_end = n_string_end+1 else exit do end if loop n_string_start = n_string_end n_string_end = instr(n_string_start, szResult, " ") sinterface(1,narray_count) = mid(szResult, n_string_start,n_string_end - n_string_start) 'msgbox sinterface(0, narray_count) & ", " & sinterface(1, narray_count) icount = instr(n_string_end, szResult, chr(13)) narray_count = narray_count+1 'msgbox (sinterface & chr(13) & len(szResult) & chr(13) & icount) loop 'grab MAC addresses 'For i=0 to narray_count current_interface = sinterface(0,5) command = "show interface " & current_interface & " | include address" & chr(13) msgbox command crt.Screen.Send command crt.Screen.WaitForString szStartString 'next 'develop write string wstring = szStartString & vbnewline wstring = wstring & "OS=" & sverion & vbnewline wstring = wstring & "IMAGE=" & simage_file & vbnewline wstring = wstring & "MODEL=" & smodel & vbnewline & vbnewline wstring = wstring & "INTERFACES" & vbnewline for i=0 to narray_count wstring = wstring & sinterface(0,i) & "," & sinterface(1,i) & vbnewline next call WriteFileText("\\serverpath", wstring) 'test display for results msgbox (sverion & chr(13) & simage_file & chr(13) & smodel) 'crt.Session.Disconnect End sub Function ReadFull(more,prompt) strCompleteOutput="" Do ' Capture the result into a script variable. ' Have ReadString() return after it sees one of the ' supplied strings "pixfirewall#" or the ' "...More..." tag. strResult=crt.Screen.ReadString(more,prompt) ' Append the results we've got so far to the complete ' results that are being accumulated. strCompleteOutput = strCompleteOutput & strResult ' If a "More" was found, send a space to get the next ' page of output from the remote If crt.Screen.MatchIndex = 1 Then crt.Screen.Send " " end if ' If the shell prompt was found, then we've received ' all of the output expected to have been sent from ' the remote. If crt.Screen.MatchIndex = 2 Then Exit Do end if Loop ' A Cisco PIX sends each line followed by a line feed (LF) ' and a Carriage return (CR). Take care of each line that ' would have had "<--- More --->" on it. Depending on the way ' your device tries to "erase" the "<--- More --->" prompt, you ' may need to change the replace string below. strCompleteOutput = Replace(strCompleteOutput, " " & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & " " & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8) & chr(8), "") ReadFull = strCompleteOutput end function Function WriteFileText(sFilePath, sText) Dim objFSO 'As FileSystemObject Dim objTextFile 'As Object Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile(sFilePath, True) ' Write a line. objTextFile.Write (sText) objTextFile.Close 'objTextFile.Close End Function Last edited by gunslingor; 05-21-2013 at 03:14 PM. |
#2
|
|||
|
|||
Alright, nevermind...lol...sorry.... apparently there is a carriage return before each element in the array. It is odd though. MS notepad seems to completely ignore any chr(13)s that are outputted to a text file... that's why I thought there were no carriage returns at first. notepad does appear to recognize vbnewline. Moderator may delete thread, your choice.
Last edited by gunslingor; 05-22-2013 at 06:34 AM. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|