Scriptomatic takes the troublesome out of it, imho.
returns all IPs and their corresponding subnets. Commented lines, if uncommented, will ask for an IP and retrieve only the subnet for that IP (if none found then returned all). Seemed less efficient than just looking at the entire list, but you may find a use.
;~ $IP = inputbox ("Which IP?" , "Which IP do you want the subnet for?")
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$FOutput=""
$objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
For $objItem In $colItems
$strIPAddress = $objItem.IPAddress(0)
If $strIPAddress <> "" Then $FOutput &= $strIPAddress & @CRLF
$strIPSubnet = $objItem.IPSubnet(0)
If $strIPSubnet <> "" Then $FOutput &= $strIPSubnet & @CRLF & @CRLF
;~ If $strIPAddress = $IP Then $Output &= $strIPSubnet
Next
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
Endif
;~ If $output <> "" Then
;~ msgbox (0, '' , $output)
;~ Else
msgbox (0, '' , $Foutput)
;~ Endif
Func WMIDateStringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc