Jump to content

Recommended Posts

Posted

Hello,

I found the function GetIpAddrTable here  but it did not work for me, so I decided to rewrite it and make a useful function out of it.

As always I hope someone needs it!

 

#include <Array.au3>

Global $aIpTable = _GetIpAddrTable()
_ArrayDisplay($aIpTable)




Func _GetIpAddrTable($bOrder = 0)
;funkey 2013, Aug 17th
Local Const $tagMIB_IPADDRROW = "STRUCT;DWORD dwAddr;DWORD dwIndex;DWORD dwMask;DWORD dwBCastAddr;DWORD dwReasmSize;USHORT unused1;USHORT wType;ENDSTRUCT;"
Local Const $tagMIB_IPADDRTABLE = "DWORD dwNumEntries;" & $tagMIB_IPADDRROW

Local Const $MIB_IPADDR_PRIMARY = 0x0001
Local Const $MIB_IPADDR_DYNAMIC = 0x0004
Local Const $MIB_IPADDR_DISCONNECTED = 0x0008
Local Const $MIB_IPADDR_DELETED = 0x0040
Local Const $MIB_IPADDR_TRANSIENT = 0x0080

Local $aRet, $dwSize, $dwNumEntries, $tMIB_IPADDRTABLE, $tagTemp = $tagMIB_IPADDRTABLE
Local $iIpAddrRowSize = 24, $iSize = 28, $aTemp, $iTemp

$aRet = DllCall("iphlpapi.dll", "int", "GetIpAddrTable", "ptr", 0, "DWORD*", 0, "BOOL", $bOrder)
$dwSize = $aRet[2]
While $iSize < $dwSize
$tagTemp &= $tagMIB_IPADDRROW
$iSize += $iIpAddrRowSize
WEnd

$tMIB_IPADDRTABLE = DllStructCreate($tagTemp)

$aRet = DllCall("iphlpapi.dll", "int", "GetIpAddrTable", "struct*", $tMIB_IPADDRTABLE, "DWORD*", $dwSize, "BOOL", $bOrder)
If $aRet[0] <> 0 Then Return SetError(1, 0, 0)

$dwNumEntries = DllStructGetData($tMIB_IPADDRTABLE, "dwNumEntries")

Local $aData[$dwNumEntries + 1][6] = [["Interface Index", "IP Address", "Subnet Mask", "Broadcast", "Reassembly size", "Type and State"]]
For $i = 1 To $dwNumEntries
$aData[$i][0] = DllStructGetData($tMIB_IPADDRTABLE, ($i - 1) * 7 + 3)
$aTemp = DllCall("ws2_32.dll", "str", "inet_ntoa", "ptr", DllStructGetData($tMIB_IPADDRTABLE, ($i - 1) * 7 + 2))
$aData[$i][1] = $aTemp[0]
$aTemp = DllCall("ws2_32.dll", "str", "inet_ntoa", "ptr", DllStructGetData($tMIB_IPADDRTABLE, ($i - 1) * 7 + 4))
$aData[$i][2] = $aTemp[0]
$aTemp = DllCall("ws2_32.dll", "str", "inet_ntoa", "ptr", DllStructGetData($tMIB_IPADDRTABLE, ($i - 1) * 7 + 5))
$aData[$i][3] = $aTemp[0]
$aData[$i][4] = DllStructGetData($tMIB_IPADDRTABLE, ($i - 1) * 7 + 6)
$iTemp = DllStructGetData($tMIB_IPADDRTABLE, ($i - 1) * 7 + 8)
If BitAND($iTemp, $MIB_IPADDR_PRIMARY) Then $aData[$i][5] &= "Primary IP Address;"
If BitAND($iTemp, $MIB_IPADDR_DYNAMIC) Then $aData[$i][5] &= "Dynamic IP Address;"
If BitAND($iTemp, $MIB_IPADDR_DISCONNECTED) Then $aData[$i][5] &= "Address is on disconnected interface;"
If BitAND($iTemp, $MIB_IPADDR_DELETED) Then $aData[$i][5] &= "Address is being deleted;"
If BitAND($iTemp, $MIB_IPADDR_TRANSIENT) Then $aData[$i][5] &= "Transient address;"
$aData[$i][5] = StringTrimRight($aData[$i][5], 1)
Next

Return $aData
EndFunc ;==>_GetIpAddrTable
 

Best regards

funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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
×
×
  • Create New...