if you're still interested, this is the way via Iphlpapi.dll:
$theIP1 = @IPAddress1
$subnetIP = _GetSubnetBasedOnIP($theIP1)
if NOT @error then
Local $type = ''
Switch @extended
Case 0
$type = 'Regular adapter IP'
Case 1
$type = 'Gateway IP'
Case 2
$type = 'DHCP Server IP'
Case 3
$type = 'PrimaryWinsServer IP'
Case 4
$type = 'SecondaryWinsServer IP'
Case Else
$type = 'Unknown IP'
EndSwitch
MsgBox(0, 'Success', 'For IP:' & @TAB & $theIP1 & @CRLF & 'Subnet is:' & @TAB & $subnetIP & @CRLF & 'IP Type:' & @TAB & $type)
Else
Switch @error
Case 1
MsgBox(0, 'Error 1', 'Input IP [' & $theIP1 & '] is not a valid IP address.')
Case 2
MsgBox(0, 'Error 2', 'Input IP [' & $theIP1 & '] was not found on this computer.')
Case 3
MsgBox(0, 'Error 3', 'dll open: Iphlpapi.dll, error code: ' & @extended)
Case 4
MsgBox(0, 'Error 4', 'dll call function: GetAdaptersInfo, error code: ' & @extended)
Case 5
MsgBox(0, 'Error 5', 'dll call function: GetAdaptersInfo with adapter buffer pointer, error code: ' & @extended)
Case Else
MsgBox(0, 'Error X', 'Unknown error occured for the input IP [' & $theIP1 & '].')
EndSwitch
EndIf
;==========================================================================================================================================================
;==========================================================================================================================================================
Func _GetSubnetBasedOnIP($theIP)
if NOT _isIPaddr($theIP) Then Return SetError(1, 0, 0)
Local Const $tagIP_ADDRESS_STRING = "char IPAddress[16];"
Local Const $tagIP_MASK_STRING = "char IPMask[16];"
Local Const $tagIP_ADDR_STRING = "ptr Next;" & $tagIP_ADDRESS_STRING & $tagIP_MASK_STRING & "DWORD Context;"
Local Const $tagIP_ADAPTER_INFO = "ptr Next; DWORD ComboIndex; char AdapterName[260];char Description[132]; UINT AddressLength; BYTE Address[8]; dword Index; UINT Type;" & _
" UINT DhcpEnabled; ptr CurrentIpAddress; ptr IpAddressListNext; char IpAddressListADDRESS[16]; char IpAddressListMASK[16]; DWORD IpAddressListContext; " & _
"ptr GatewayListNext; char GatewayListADDRESS[16]; char GatewayListMASK[16]; DWORD GatewayListContext; " & _
"ptr DhcpServerNext; char DhcpServerADDRESS[16]; char DhcpServerMASK[16]; DWORD DhcpServerContext; " & _
"int HaveWins; " & _
"ptr PrimaryWinsServerNext; char PrimaryWinsServerADDRESS[16]; char PrimaryWinsServerMASK[16]; DWORD PrimaryWinsServerContext; " & _
"ptr SecondaryWinsServerNext; char SecondaryWinsServerADDRESS[16]; char SecondaryWinsServerMASK[16]; DWORD SecondaryWinsServerContext; " & _
"DWORD LeaseObtained; DWORD LeaseExpires;"
Local $dll = DllOpen("Iphlpapi.dll")
If @error then Return SetError(3, @error, 0)
Local $ret = DllCall($dll, "dword", "GetAdaptersInfo", "ptr", 0, "dword*", 0)
If @error then
DllClose($dll)
Return SetError(4, @error, 0)
EndIf
Local $adapterBuffer = DllStructCreate("byte[" & $ret[2] & "]")
Local $adapterBuffer_pointer = DllStructGetPtr($adapterBuffer)
DllCall($dll, "dword", "GetAdaptersInfo", "ptr", $adapterBuffer_pointer, "dword*", $ret[2])
If @error then
$adapterBuffer = ""
$adapterBuffer_pointer = ""
DllClose($dll)
Return SetError(5, @error, 0)
EndIf
Local $adapter = DllStructCreate($tagIP_ADAPTER_INFO, $adapterBuffer_pointer)
Local $IPType = -1
Local $FoundIt = False
Local $retVal = ""
Do
Local $allArray = _GetAllIps(DllStructGetPtr($adapter, "IpAddressListNext"), $tagIP_ADDR_STRING)
if IsArray($allArray) Then
For $i = 0 to UBound($allArray)-1
if NOT _isIPaddr($allArray[$i][0]) then ContinueLoop
if $allArray[$i][0] <> $theIP Then ContinueLoop
if NOT _isIPaddr($allArray[$i][1]) then ContinueLoop
$retVal = $allArray[$i][1]
$IPType = 0
$FoundIt = True
ExitLoop
Next
EndIf
if NOT $FoundIt Then
$allArray = _GetAllIps(DllStructGetPtr($adapter, "GatewayListNext"), $tagIP_ADDR_STRING)
if IsArray($allArray) Then
For $i = 0 to UBound($allArray)-1
if NOT _isIPaddr($allArray[$i][0]) then ContinueLoop
if $allArray[$i][0] <> $theIP Then ContinueLoop
if NOT _isIPaddr($allArray[$i][1]) then ContinueLoop
$retVal = $allArray[$i][1]
$IPType = 1
$FoundIt = True
ExitLoop
Next
EndIf
EndIf
if NOT $FoundIt Then
Local $ptr1 = DllStructGetPtr($adapter, "DhcpServerNext")
Local $IPStruct = DllStructCreate($tagIP_ADDR_STRING,$ptr1)
Local $curIP = DllStructGetData($IPStruct,"IPAddress")
Local $curSubnet = DllStructGetData($IPStruct,"IPMask")
if _isIPaddr($curIP) AND _isIPaddr($curSubnet) Then
if $curIP = $theIP then
$retVal = $curSubnet
$IPType = 2
$FoundIt = True
EndIf
EndIf
EndIf
if NOT $FoundIt Then
Local $ptr1 = DllStructGetPtr($adapter, "PrimaryWinsServerNext")
Local $IPStruct = DllStructCreate($tagIP_ADDR_STRING,$ptr1)
Local $curIP = DllStructGetData($IPStruct,"IPAddress")
Local $curSubnet = DllStructGetData($IPStruct,"IPMask")
if _isIPaddr($curIP) AND _isIPaddr($curSubnet) Then
if $curIP = $theIP then
$retVal = $curSubnet
$IPType = 3
$FoundIt = True
EndIf
EndIf
EndIf
if NOT $FoundIt Then
Local $ptr1 = DllStructGetPtr($adapter, "SecondaryWinsServerNext")
Local $IPStruct = DllStructCreate($tagIP_ADDR_STRING,$ptr1)
Local $curIP = DllStructGetData($IPStruct,"IPAddress")
Local $curSubnet = DllStructGetData($IPStruct,"IPMask")
if _isIPaddr($curIP) AND _isIPaddr($curSubnet) Then
if $curIP = $theIP then
$retVal = $curSubnet
$IPType = 4
$FoundIt = True
EndIf
EndIf
EndIf
if $FoundIt Then ExitLoop
$ptr = DllStructGetData($adapter, "Next")
$adapter = DllStructCreate($tagIP_ADAPTER_INFO, $ptr)
Until @error
$adapterBuffer = ""
$adapterBuffer_pointer = ""
DllClose($dll)
if NOT $FoundIt Then Return SetError(2, 0, 0)
Return SetError(0, $IPType, $retVal)
EndFunc
Func _GetAllIps($Ptr, $tagIP_ADDR_STRING)
Local $IPStruct, $Index = 0
Local $IPArray[1][3]
Do
ReDim $IPArray[$Index+1][3]
$IPStruct = DllStructCreate($tagIP_ADDR_STRING,$ptr)
$IPArray[$Index][0] = DllStructGetData($IPStruct,"IPAddress")
$IPArray[$Index][1] = DllStructGetData($IPStruct,"IPMask")
$IPArray[$Index][2] = DllStructGetData($IPStruct,"Context")
$Ptr = DllStructGetData($IPStruct,"Next")
$Index += 1
Until $Ptr = 0
Return $IPArray
EndFunc
Func _isIPaddr($sIPAddr)
If NOT StringRegExp($sIPAddr, "^((25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(25[0-5]|2[0-4]\d|[01]?\d?\d)$") Then Return SetError(1, 0, False)
Return True
EndFunc