Announcement

Collapse
No announcement yet.

Need help with "get IP from specific NIC" script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with "get IP from specific NIC" script

    Hello,

    I need some help with a script. I have enough knowledge of scripts to modify them to get them work, but it would take a long time for me to create one from scratch.

    I know what needs to be done to accomplish this task, but I don’t know the language.

    The scenario:
    We have staff that must connect using Cisco VPN client. The problem that we have is that our internal IP address is on the 192.168.1.0 subnet, and when the staff are at home or a hotel with the same IP scheme, they cannot connect to their remote desktop. The solution is to add a ROUTE statement directing all traffic meant for the remote desktop IP through the VPN Client’s IP address. The format of the ROUTE statement is

    ROUTE ADD <destination IP> MASK <mask> <gateway IP>

    Example:
    Route add 192.168.2.100 MASK 255.255.255.255 10.1.1.51

    The manual way to do this is:
    1. Start > Run
    2. Type in CMD and press <ENTER>
    3. Type ipconfig and get the Cisco VPN IP address (the new gateway address)
    4. Type the above ROUTE ADD statement and insert the appropriate gateway IP address

    Our staff members, however, are not as computer savvy as we would like. The Remote Desktop IP is always STATIC. Because the VPN IP address can change, we can’t create a static script that will work every time.

    I have found scripts on these forums that return the IP address, but I need to be able to return the IP address for the interface (adapter) with the word “Cisco” in the description. I must then insert that variable into a shell command that contains the ROUTE ADD statement.

    There are many people looking for a way to bypass this problem of matching VPN subnets aside from changing the IP scheme, so I predict this script will be useful for many people.

    Can anyone help me out please?

    Thanks!

  • #2
    Re: Need help with &quot;get IP from specific NIC&quot; script

    You can try this. I did not have a VPN tunnel to test with but it worked with other adapters.

    Code:
    strComputer = "."
    strNIC = "Cisco"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colAdapterConfigs = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                            wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
    
    For Each objAdapterConfigs In colAdapterConfigs
      If InStr(objAdapterConfigs.Description, strNIC) > 0 Then
        strIPAddress = Join(objAdapterConfigs.IPAddress, ",")
        Exit For
      End If
    Next
    
    set objShell = CreateObject("WScript.Shell") 
    objShell.Run "Route add 192.168.2.100 MASK 255.255.255.255 " & strIPAddress
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Need help with &quot;get IP from specific NIC&quot; script

      Wow. That's much less code than I thought it would be. The "get IP" scripts I was looking at were much more involved. Your script does exactly what I need it to do. I'll test it with my remote workers today.

      Comment


      • #4
        Re: Need help with &quot;get IP from specific NIC&quot; script

        Cool. Let me know how it turns out.
        Regards,
        Jeremy

        Network Consultant/Engineer
        Baltimore - Washington area and beyond
        www.gma-cpa.com

        Comment

        Working...
        X