AU3网卡信息api获取GetAdaptersInfo
1 #include <Array.au3> 2 #cs 3 DWORD GetAdaptersInfo( 4 __out PIP_ADAPTER_INFO pAdapterInfo, ; IP_ADAPTER_INFO 结构指针。 5 __inout PULONG pOutBufLen ; IP_ADAPTER_INFO 结构大小。 6 ); 7 8 PIP_ADAPTER_INFO - IP_ADAPTER_INFO结构指针,结构定义如下: 9 typedef struct _IP_ADAPTER_INFO { 10 struct _IP_ADAPTER_INFO *Next; ; 下一块网卡信息的起始地址 11 DWORD ComboIndex; 12 char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4]; 13 char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]; 14 UINT AddressLength; 15 BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]; 16 DWORD Index; 17 UINT Type; 18 UINT DhcpEnabled; 19 PIP_ADDR_STRING CurrentIpAddress; 20 IP_ADDR_STRING IpAddressList; 21 IP_ADDR_STRING GatewayList; 22 IP_ADDR_STRING DhcpServer; 23 BOOL HaveWins; 24 IP_ADDR_STRING PrimaryWinsServer; 25 IP_ADDR_STRING SecondaryWinsServer; 26 time_t LeaseObtained; 27 time_t LeaseExpires; 28 }IP_ADAPTER_INFO, *PIP_ADAPTER_INFO; 29 30 IP_ADDR_STRING - 结构定义如下: 31 struct _IP_ADDR_STRING *Next; 32 IP_ADDRESS_STRING IpAddress; ; IP 地址 33 IP_MASK_STRING IpMask; ; 子网掩码 34 DWORD Context; 35 }IP_ADDR_STRING, *PIP_ADDR_STRING; 36 37 AutoIt IP_ADDR_STRING 结构定义如下: 38 ptr Next;char IpAddr[16];char IpMask[16];dword Context 39 40 41 AutoIt IP_ADAPTER_INFO 结构定义如下: 42 43 ptr NextAdpt; dword ComboIndex; char AdptName[260]; char AdptDescr[132];uint AddrLength;byte MacAddr[8];dword Index;uint Type; uint DhcpEnabled;ptr 44 45 CurrentIpAddr;ptr NextIpAddr; char IpAddr[16];char IpAddrMask[16]; dword IpAddrCxt; ptr NextGateway; char GatewayAddr[16]; char GatewayAddrMask 46 47 [16];dword GatewayCxt; ptr NextDhcp; char DhcpAddr[16]; char DhcpAddrMask[16];dword DhcpCxt; int HaveWins; ptr NextPriWinsServer; char 48 49 PriWinsServerAddr[16]; char PriWinsServerAddrMask[16]; dword PriWinsServerCxt; ptr NextSecWinsServer; char SecWinsServerAddr[16]; char 50 51 SecWinsServerAddrMask[16]; dword LeaseObtained; dword LeaseExpires 52 53 54 55 PULONG - IP_ADAPTER_INFO,结构大小. 56 #ce 57 58 Func _GetAdaptersInfo() 59 Local $iResult, $tBuffer, $pBuffer, $aResult[1][9], $tagADPTINFO, $tAdpt 60 61 ; 第一次调用传递空值,pOutBufLen ( $iResult[2] ) 设为结构所需大小,单位byte。 62 $iResult = DllCall("iphlpapi.dll", "dword", "GetAdaptersInfo", "ptr", 0, "ulong*", 0) 63 $tBuffer = DllStructCreate("byte[" & $iResult[2] & "]") ; 定义$iResult[2] 字节的缓存区域 (分配内存空间)。 64 $pBuffer = DllStructGetPtr($tBuffer) ; 获取内存指针。 65 66 ; 第二次调用,GetAdaptersInfo把网卡信息复制到指定的内存空间 ($tBuffer) 中。 67 $iResult = DllCall("iphlpapi.dll", "dword", "GetAdaptersInfo", "ptr", $pBuffer, "ulong*", $iResult[2]) 68 ; $iResult[0]值为0则调用成功,否则为系统错误号。 69 70 ; 数据转换, byte --> IP_ADAPTER_INFO 71 72 $tagADPTINFO = "ptr NextAdpt; dword ComboIndex; char AdptName[260]; char AdptDescr[132];uint AddrLength;byte MacAddr[8];dword Index;uint Type; uint DhcpEnabled;ptr CurrentIpAddr;ptr NextIpAddr; char IpAddr[16];char IpAddrMask[16]; dword IpAddrCxt; ptr NextGateway; char GatewayAddr[16];char GatewayAddrMask[16];dword GatewayCxt; ptr NextDhcp; char DhcpAddr[16]; char DhcpAddrMask[16];dword DhcpCxt; int HaveWins; ptr NextPriWinsServer; char PriWinsServerAddr[16]; char PriWinsServerAddrMask[16]; dword PriWinsServerCxt; ptr NextSecWinsServer; char SecWinsServerAddr[16];char SecWinsServerAddrMask[16]; dword LeaseObtained; dword LeaseExpires" 73 74 While $pBuffer 75 $tAdpt = DllStructCreate($tagADPTINFO, $pBuffer) 76 $aResult[0][0] += 1 77 ReDim $aResult[$aResult[0][0] + 1][9] 78 $aResult[$aResult[0][0]][0] = DllStructGetData($tAdpt, "AdptName") ; 网卡名称 79 $aResult[$aResult[0][0]][1] = DllStructGetData($tAdpt, "AdptDescr") ; 网卡描述 80 $aResult[$aResult[0][0]][2] = DllStructGetData($tAdpt, "MacAddr") ; 网卡MAC 81 $aResult[$aResult[0][0]][3] = DllStructGetData($tAdpt, "Index") ; 网卡索引号 82 $aResult[$aResult[0][0]][4] = DllStructGetData($tAdpt, "Type") ; 类型 83 $aResult[$aResult[0][0]][5] = DllStructGetData($tAdpt, "DhcpEnabled") ; DHCP是否启用 true = 启用, false = 禁用 84 $aResult[$aResult[0][0]][6] = DllStructGetData($tAdpt, "IpAddr") ; IP 地址 85 $aResult[$aResult[0][0]][7] = DllStructGetData($tAdpt, "GatewayAddr") ; 网关地址 86 $aResult[$aResult[0][0]][8] = DllStructGetData($tAdpt, "DhcpAddr") ; DHCP地址, 只有DhcpEnabled为true时,此值才有效。 87 $pBuffer = DllStructGetData($tAdpt, "NextAdpt") ; [下一张网卡信息的内存地址。] 88 $tAdpt = 0 89 WEnd 90 $tBuffer = 0 91 Return SetError($iResult[0], 0, $aResult) 92 EndFunc ;==>_GetAdaptersInfo 93 94 95 $a = _GetAdaptersInfo() 96 _ArrayDisplay($a, @error)
本文来自博客园,作者:hdlan,转载请注明原文链接:https://www.cnblogs.com/hdlan/articles/13685523.html