all needed information in IP_ADAPTER_ADDRESSES structure I manged reasonably. Just trying to get information which are exposed by Pointers I completely struggle.
Any hint or support is very much appreciated.
Code: Select all
#Persistent
#warn
OutPut := GetAdaptersAddresses()
PrintArr(OutPut)
GetAdaptersAddresses()
{
vAdapterAddresses := A_PtrSize ? "Ptr" : "UInt"
vSizePointer := A_PtrSize ? "Ptr" : "UInt"
vSizePointer := 0
; initial call to GetAdaptersAddresses to get the necessary size
vResult := DllCall("iphlpapi.dll\GetAdaptersAddresses", "Int", 0, "Int", 0, "UPTR", 0, "UPTR", &vAdapterAddresses, "UPTR", &vSizePointer)
if ( vResult = 111) ; ERROR_BUFFER_OVERFLOW
{
;msgbox %vResult% . " / " . %vSizePointer%
if !(VarSetCapacity(vAdapterAddresses, vSizePointer, 0)) ; vSizePointer ==> 1x = 704 | 2x = 1408 | 3x = 2112
{
msgbox "Memory allocation failed for IP_ADAPTER_INFO struct"
return "Memory allocation failed for IP_ADAPTER_INFO struct"
}
}
; second call to GetAdapters Addresses to get the actual data we want
vResult := DllCall("iphlpapi.dll\GetAdaptersAddresses", "UInt", 0, "UInt", 0, "UPTR", 0, "UPTR", &vAdapterAddresses, "UPTR", &vSizePointer)
if ( vResult != 0) ; NO_ERROR / ERROR_SUCCESS
{
msgbox "Call to GetAdaptersAddresses failed with error: " %vResult%
return "Call to GetAdaptersAddresses failed with error: " vResult
}
; get some information from the data we received
addr := &vAdapterAddresses+0, IP_ADAPTER_ADDRESSES := {}
y := &vSizePointer
msgbox "addr = " %addr% " / length " %y%
iaddr := addr
while (addr)
{
IP_ADAPTER_ADDRESSES [A_Index, "addr"] := addr
vLength := NumGet(addr+0, o := 0, "UINT") , o += A_PtrSize ; 0
IP_ADAPTER_ADDRESSES [A_Index, "vLength"] := vLength
vIfIndex := NumGet(addr+0, o , "UINT") , o += A_PtrSize ; 4
IP_ADAPTER_ADDRESSES [A_Index, "ifIndex"] := vIfIndex
vNext := NumGet(addr+0, o , "UINT") , o += A_PtrSize ; 8
; IP_ADAPTER_ADDRESSES [A_Index, "Next"] := vNext
pAdapterName := NumGet(addr+0, o, "UPTR"), o += A_PtrSize ; 12
vAdapterName := StrGet(pAdapterName, "CP0")
IP_ADAPTER_ADDRESSES [A_Index, "AdapterName"] := vAdapterName
pFirstUnicastAddress := NumGet(addr+0, o, "UPTR"), o += A_PtrSize ;16
vTest := NumGet(pFirstUnicastAddress, 12, "UINT")
IP_ADAPTER_ADDRESSES [A_Index, "FirstUnicastAddress"] := pFirstUnicastAddress
pFirstAnycastAddress := NumGet(addr+0, o, "UPTR") , o += A_PtrSize ;20
IP_ADAPTER_ADDRESSES [A_Index, "FirstAnycastAddress"] := pFirstAnycastAddress
pFirstMulticastAddress := NumGet(addr+0, o, "UPTR") , o += A_PtrSize ;24
IP_ADAPTER_ADDRESSES [A_Index, "FirstMulticastAddress"]:= pFirstMulticastAddress
IP_ADAPTER_ADDRESSES [A_Index, "a_pos"] := o
pFirstDnsServerAddress := NumGet(addr+0, o, "UPTR") , o += A_PtrSize ;28
; lpsaAddress := NumGet(pFirstDnsServerAddress, 12, "PTR") ;8 ;10.0.0.1
; dwAddressLength := NumGet(pFirstDnsServerAddress, 16, "INT") ;8 ;10.0.0.1
; vTest := DllCall("Ws2_32.lib\WSAAddressToString", "UPTR", lpsaAddress, "UPTR", dwAddressLength, "UPTR", 0, "UPTR", &lpszAddressString, "UPTR", &lpdwAddressStringLength)
IP_ADAPTER_ADDRESSES [A_Index, "DnsTest"] := vTest
IP_ADAPTER_ADDRESSES [A_Index, "FirstDnsServerAddress"]:= pFirstDnsServerAddress
; msgbox %A_Index% " / " %pFirstDnsServerAddress% ;" / " %vDnsLength% " / " %t%
pDnsSuffix := NumGet(addr+0, o, "UINT") , o += A_PtrSize ;32
vDnsSuffix := StrGet(pDnsSuffix)
IP_ADAPTER_ADDRESSES [A_Index, "DnsSuffix"] := vDnsSuffix
pDescription := NumGet(addr+0, o, "UINT"), o += A_PtrSize ;36
vDescription := StrGet(pDescription)
IP_ADAPTER_ADDRESSES [A_Index, "Description"] := vDescription
pFriendlyName := NumGet(addr+0, o, "UINT"), o += A_PtrSize ;40
vFriendlyName := StrGet(pFriendlyName )
IP_ADAPTER_ADDRESSES [A_Index, "FriendlyName"] := vFriendlyName
pPhysicalAddressLength := NumGet(addr+0, o + 8, "UCHAR") ;52
IP_ADAPTER_ADDRESSES [A_Index, "PhysicalAddressLength"]:= pPhysicalAddressLength
mac :=""
loop % pPhysicalAddressLength
mac .= Format("{:02X}", NumGet(addr+0, o + A_Index - 1, "UChar")) "-"
IP_ADAPTER_ADDRESSES[A_Index, "Address"] := SubStr(mac, 1, -1), mac := "", o += 12 ;44
pFlags := NumGet(addr+0, o, "UINT"), o += 4 ;56
IP_ADAPTER_ADDRESSES [A_Index, "Flags"] := pFlags
pMtu := NumGet(addr+0, o, "UINT"), o += 4 ;60
IP_ADAPTER_ADDRESSES [A_Index, "Mtu"] := pMtu
pIfType := NumGet(addr+0, o, "UINT"), o += 4 ;64
IP_ADAPTER_ADDRESSES [A_Index, "ifType"] := pIfType
pIfOperStatus := NumGet(addr+0, o, "UINT"), o += 4 ;68
IP_ADAPTER_ADDRESSES [A_Index, "ifOperStatus"] := pIfOperStatus
;msgbox "test : " . %addr%+0
addr := vNext
}
;msgbox "test : " . NumGet(addr+0, o := A_PtrSize, "UInt")
; output the data we received and free the buffer
return IP_ADAPTER_ADDRESSES, VarSetCapacity(vAdapterAddresses, 0), VarSetCapacity(addr, 0)
}
PrintArr(Arr, Option := "w1200 h200", GuiNum := 90)
{
cnt:=0
for index, obj in Arr {
if (A_Index = 1) {
for k, v in obj {
Columns .= k "|"
cnt++
}
Gui, %GuiNum%: Margin, 5, 5
Gui, %GuiNum%: Add, ListView, %Option%, % Columns
}
RowNum := A_Index
Gui, %GuiNum%: default
LV_Add("")
for k, v in obj {
LV_GetText(Header, 0, A_Index)
if (k <> Header) {
FoundHeader := False
loop % LV_GetCount("Column") {
LV_GetText(Header, 0, A_Index)
if (k <> Header)
continue
else {
FoundHeader := A_Index
break
}
}
if !(FoundHeader) {
LV_InsertCol(cnt + 1, "", k)
cnt++
ColNum := "Col" cnt
} else
ColNum := "Col" FoundHeader
} else
ColNum := "Col" A_Index
LV_Modify(RowNum, ColNum, (IsObject(v) ? "Object()" : v))
}
}
loop % LV_GetCount("Column")
LV_ModifyCol(A_Index, "AutoHdr")
Gui, %GuiNum%: Show,, Array
}