Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-02-2019, 06:49 PM
ghostm ghostm is offline
Registered User
 
Join Date: Sep 2019
Posts: 2
Resovling IP Address in SecureCRT Output

Hello All,

Can someone help me by provide script or guide me in a way to resolve the IP address in the SecureCRT output? For example, the following show bgp has a couple of ip address and I want it to be resolved in the outputs (10.222.15.6, 10.222.25.11, and 192.168.250.202).

Code:
RP/0/RP0/CPU0:Core-DMZ#show bgp vrf Internet_1 10.70.8.0/24                           
Sat May 18 13:24:53.350 EDT
BGP routing table entry for 10.70.8.0/24  , Route Distinguisher: 66601:2333
Versions:
  Process           bRIB/RIB  SendTblVer
  Speaker          141665594   141665594
Last Modified:
Paths: (1 available, best #1)
  Advertised to CE peers (in unique update groups):
    10.222.15.6     
  Path #1: Received by speaker 0
  Advertised to CE peers (in unique update groups):
    10.222.15.6     
  26810, (received & used)
    10.222.25.11 (metric 3) from 192.168.250.202 (10.222.25.11)
      Received Label 163
      Origin IGP, localpref 120, valid, confed-internal, best, group-best, import-candidate, imported
      Received Path ID 0, Local Path ID 1, version 14166
      Community: 123:321
      Extended community: RT:60001:600 
      Source VRF: default, Source Route Distinguisher: 66661:2111
RP/0/RP0/CPU0:Core-DMZ#
Thanks

Moh

Last edited by jdev; 09-03-2019 at 02:29 PM. Reason: wrap device output in [code] blocks
Reply With Quote
  #2  
Old 09-03-2019, 02:48 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 938
Quote:
Originally Posted by ghostm View Post
Can someone help me by provide script or guide me in a way to resolve the IP address in the SecureCRT output? For example, the following show bgp has a couple of ip address and I want it to be resolved in the outputs (10.222.15.6, 10.222.25.11, and 192.168.250.202).
Hello Moh,

"resolved in the outputs" could mean different things depending on the context.

Are you saying you'd like the IP addresses to be replaced with the corresponding host names?

And that you'd like the host names to be displayed on the screen instead of the IP addresses?

If I'm not understanding what you're asking, please clarify.

If I understand what you want, then the answer to your question is: There is no such script. While it may be possible to perform a reverse lookup on an IP address to convert it to a host name, replacing the IP address on the screen with the corresponding host name would be problematic. For one, the resolved host name will almost always be of a different length (in characters) than the IP address. Also, there is no easy way through scripting to "replace" text on the screen.

There are a couple of options you could consider pursuing... but, before we can discuss any examples, we would need to know more info.

What version of SecureCRT are you using?

What operating system is SecureCRT installed and running on?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 09-04-2019, 11:51 AM
ghostm ghostm is offline
Registered User
 
Join Date: Sep 2019
Posts: 2
Resovling IP Address in SecureCRT

Hello Jake,

Thank you for your reply and sorry for the confusion.
The answer to your question is I like the host names to be displayed on the screen instead of the IP addresses.

What version of SecureCRT are you using? Version 8.0.0
What operating system is SecureCRT installed and running on? Windows 10


Moh
Reply With Quote
  #4  
Old 09-04-2019, 02:37 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 938
Quote:
Originally Posted by ghostm View Post
The answer to your question is I like the host names to be displayed on the screen instead of the IP addresses.
If that's the case, I don't have any scripting solution ideas that would work for you. SecureCRT is told by the connected host exactly what to display on the screen. Deciding to display something different (like a reverse name lookup of an IP address rather than the IP address itself) would be quite the undertaking beyond the scope of SecureCRT's current scripting API.

I've created a feature request for you to have the ability to somehow more easily display IP addresses in hostname format, having SecureCRT attempt a reverse name lookup to somehow get the host name. I don't have any ETA as to when (if ever) such a feature might be available, but if anything ever materializes we'll be sure to post here.

As a workaround, you could write a script that would scrape the current screen looking for IP addresses...
Code:
' Get the current screen
strScreenText = crt.Screen.Get2(1, 1, crt.Screen.Rows, crt.Screen.Columns)
Set cIPs = CreateObject("Scripting.Dictionary")
Set cIndices = CreateObject("Scripting.Dictionary")

' Set up some IP address patterns we can use to detect and extract all
' IP addresses that exist on the current screen
strOctetPart = "(25[0-5]|2[0-4]\d|[01]?\d\d?)"
strIpMatch = "" & _
    "(" & strOctetPart & "\." & strOctetPart & "\." & strOctetPart & _
    "\.(?:" & strOctetPart & "|(?:" & strOctetPart & "-" & strOctetPart & ")))"
Set re = New RegExp
re.Pattern = strIpMatch
re.Global = True

' Go through each line of the screen and "capture" each
' unique IP address we find, adding the IP address to
' both an indexed collection as well as one that isn't
' indexed. Two collections aren't necessary, but having
' the two allows us to a) easily check to see if we've
' already encountered an IP address and b) easily keep
' track of the IP addresses we encounter in order from
' first to last (it's better to display results of IP
' address lookups in order from first seen to last).

nCount = 0
For Each strLine In Split(strScreenText, vbcrlf)
    If re.Test(strLine) Then
        Set objMatches = re.Execute(strLine)
        For Each objMatch in objMatches
            strCurIP = objMatch.Submatches(0)
            If Not cIPs.Exists(strCurIP) Then
                nCount = nCount + 1
                cIPs.Add strCurIP, strCurIP
                cIndices.Add nCount, strCurIP
            End If
        Next
    End If
Next

crt.Dialog.MessageBox "Here are the IPs we found on the screen:" & vbcrlf & _
    vbtab & Join(cIPs.Keys(), vbcrlf & vbtab)
...and then send each IP address to a cmd window running nslookup on each address...
Code:
' Launch a Shell object running cmd and instructing
' cmd to launch nslookup, stay open (/K) and redirect
' all stderr to stdout (2>&1):
Set g_shell = CreateObject("WScript.Shell")
Set objExec = g_shell.Exec("cmd /K nslookup 2>&1")

' Wait until the ">" character appears in the output,
' telling us it's safe to start performing lookups.
Do
    nChar = objExec.StdOut.Read(1)
Loop While nChar <> ">"

' Go through each of our IP addresses, asking the
' interactive 'nslookup' command to perform a lookup
' on the IP. As we do so, read all of the output and
' capture it for display later on:
strReport = ""
strAllOutput = ""
For nIndex = 1 to cIPs.Count
    If strReport <> "" Then strReport = strReport & vbcrlf
    strReport = strReport & nIndex & ": " & cIndices(nIndex)
    objExec.StdIn.WriteLine cIndices(nIndex)
    strReport = strReport & vbcrlf
    Do
        nChar = objExec.StdOut.Read(1)
        strReport = strReport & nChar
    Loop While nChar <> ">"
    strReport = strReport & vbcrlf
Next

' Close the cmd shell, since we're done with it.
objExec.Terminate
...and then clean up stuff a bit...
Code:
' Let's remove all of the ">" command line prompts from
' the nslookup output
strReport = Replace(strReport, vbcrlf & ">" & vbcrlf, "")

' Remove all of the other "junk" output from nslookup
Set reCleanup = New RegExp
reCleanup.Pattern = "Server:.*[\r\n]*"
reCleanup.Global = True
strReport = reCleanup.Replace(strReport, "")
reCleanup.Pattern = "Address:.*[\r\n]*"
strReport = reCleanup.Replace(strReport, "")
reCleanup.MultiLine = True
reCleanup.Pattern = "[\r\n]*Name:\s*([^\s]+)[\r\n\s]*"
strReport = reCleanup.Replace(strReport, "$1" & vbcrlf & vbcrlf)
...for display in a message box window.
Code:
' Display our results
crt.Dialog.MessageBox "Found " & cIPs.Count & " IPs" & vbcrlf & vbcrlf & strReport & vbcrlf & strAllOutput, "Results", 64
You could map such a script to a button on your button bar in SecureCRT and click it whenever you wanted to see hostnames for all IPs on the current screen.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply


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 07:53 PM.