2
votes

So, I have to set static ip's default gateways and WINS and dns and what not for a lot of windows systems both Windows 7 and XP soon. I made a batch script to help me using netsh. The problem is not every network interface name is the same. For the most part it is "Local Area Connection" but some are "Ethernet" or "Wireless Connection" and whatnot. So here is a line from my script:

netsh interface ip set address "Local Area Connection" static 192.168.%Range%.%IP_Last% 255.255.255.0 192.168.%Range%.1

Variables like %Range% are set earlier upon user input. Anyway, what I'm asking is how could I make it to where I could use:

netsh interface ip set address "%NIC_NAME%" static 192.168.%Range%.%IP_Last% 255.255.255.0 192.168.%Range%.1

So that it would work on any system. I just want it to use the currently active network card name. Thanks so much for any help!!

1

1 Answers

0
votes

You can use wmi to find active adapters, adjust below code to your need and select the name instead of ip address:

strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration" _
    & " where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then 
    For i=LBound(IPConfig.IPAddress) _
    to UBound(IPConfig.IPAddress)
    If Instr(1, IPConfig.IPAddress(i), "169.") = 0 Then 


        WScript.Echo IPConfig.IPAddress(i)
        ELSE
        END IF
    Next
End If
Next