Jump to content
Sign in to follow this  
beb7089

Retrieve Gateway address only for Telneting

Recommended Posts

beb7089

I need to write a script that will telnet into a Cisco router and and perform various commands. This script is for end-users to run on their machine and bring up an encrypted VPN tunnel connection. Telnet is our only option at this point. I can't' for the life of me figure out the best way to retrieve the Gateway (each user has a unique DHCP scope on their router so the gateway addresses are different from person to person). Please help.

Thanks

beb7089

Share this post


Link to post
Share on other sites
ptrex

@beb7089

If you run this you will see somewhere a gateway comming up

#include <date.au3>

Dim $strComputer = "."
Dim $objWMIService, $colAdapters, $n
Dim $utcLeaseObtained, $utcLeaseObtained, $utcLeaseExpired,  $strLeaseObtained, $utcLeaseExpires, $strLeaseExpires


 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

 $colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") 

$n = 1

 
For $objAdapter in $colAdapters
   ConsoleWrite ("Network Adapter " & $n & @CR)
   ConsoleWrite ("================="& @CR)
   ConsoleWrite ("  Description: " & $objAdapter.Description& @CR)
 
   ConsoleWrite ("  Physical (MAC) address: " & $objAdapter.MACAddress& @CR)
   ConsoleWrite ("  Host name:              " & $objAdapter.DNSHostName& @CR)
 
   If Not ($objAdapter.IPAddress) = " " Then
      For $i = 0 To UBound($objAdapter.IPAddress)
         ConsoleWrite ("  IP address:             " & $objAdapter.IPAddress($i)& @CR)
      Next
   EndIf
 
   If Not ($objAdapter.IPSubnet) = " " Then
      For $i = 0 To UBound($objAdapter.IPSubnet)
         ConsoleWrite ("  Subnet:                 " & $objAdapter.IPSubnet($i)& @CR)
      Next
   EndIf
 
   If Not ($objAdapter.DefaultIPGateway) = " " Then
      For $i = 0 To UBound($objAdapter.DefaultIPGateway)
         ConsoleWrite ("  Default gateway:        " & _
             $objAdapter.DefaultIPGateway($i)& @CR)
      Next
   EndIf
 
   ConsoleWrite ("  DNS"& @CR)
   ConsoleWrite ("  ---"& @CR)
   ConsoleWrite ("    DNS servers in search order:"& @CR)
 
   If Not ($objAdapter.DNSServerSearchOrder) = " " Then
      For $i = 0 To UBound($objAdapter.DNSServerSearchOrder)
         ConsoleWrite ("      " & $objAdapter.DNSServerSearchOrder($i)& @CR)
      Next
   EndIf
 
   ConsoleWrite ("    DNS domain: " & $objAdapter.DNSDomain& @CR)
 
   If Not ($objAdapter.DNSDomainSuffixSearchOrder) = " " Then
      For $i = 0 To UBound($objAdapter.DNSDomainSuffixSearchOrder)
         ConsoleWrite ("    DNS suffix search list: " & _
             $objAdapter.DNSDomainSuffixSearchOrder($i)& @CR)
      Next
   EndIf
 
   ConsoleWrite ("  DHCP"& @CR)
   ConsoleWrite ("  ----"& @CR)
   ConsoleWrite ("    DHCP enabled:        " & $objAdapter.DHCPEnabled& @CR)
   ConsoleWrite ("    DHCP server:         " & $objAdapter.DHCPServer& @CR)
 
   If Not ($objAdapter.DHCPLeaseObtained) = " " Then
      $utcLeaseObtained = $objAdapter.DHCPLeaseObtained
      $strLeaseObtained = WMIDateStringToDate($utcLeaseObtained)
   Else
      $strLeaseObtained = ""
   EndIf
   ConsoleWrite ("    DHCP lease obtained: " & $strLeaseObtained& @CR)
 
   If Not ($objAdapter.DHCPLeaseExpires) = " " Then
      $utcLeaseExpires = $objAdapter.DHCPLeaseExpires
      $strLeaseExpires = WMIDateStringToDate($utcLeaseExpires)
   Else
      $strLeaseExpires = ""
   EndIf
   ConsoleWrite ("    DHCP lease expires:  " & $strLeaseExpires& @CR)
 
   ConsoleWrite ("  WINS"& @CR)
   ConsoleWrite ("  ----"& @CR)
   ConsoleWrite ("    Primary WINS server:   " & $objAdapter.WINSPrimaryServer& @CR)
   ConsoleWrite ("    Secondary WINS server: " & $objAdapter.WINSSecondaryServer& @CR)
 
   $n = $n + 1
 
Next
 
Func WMIDateStringToDate($utcDate)
    Local $Return
   $Return = (StringMid($utcDate, 5, 2)  & "/" & _
       StringMid($utcDate, 7, 2)  & "/" & _
           StringLeft($utcDate, 4)    & " " & _
               StringMid ($utcDate, 9, 2) & ":" & _
                   StringMid($utcDate, 11, 2) & ":" & _
                      StringMid($utcDate, 13, 2))
    Return $Return
EndFunc

Enjoy !!

ptrex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×