本帖最后由 nmgwddj 于 2012-5-9 07:32 编辑
回复 2# ljxu
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 634, 246)
$ListView1 = GUICtrlCreateListView("网卡名称|MAC地址|IP地址|链路速度", 8, 40, 618, 198)
_GUICtrlListView_SetColumnWidth($ListView1, 0, 290)
$Button1 = GUICtrlCreateButton("Exit", 552, 8, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
SetListView()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button1
Exit
EndSwitch
WEnd
Func SetListView()
$a = _GetAdaptersInfo()
$index = ($a[1][3])
For $i = 1 To $a[0][0]
GUICtrlCreateListViewItem($a[$i][1] & '|' & _
StringLeft(Hex($a[$i][2]), 12) & '|' & _
$a[$i][6] & '|' & _
GetIfEntry($a[$i][3]) & ' MB', $ListView1)
Next
EndFunc ;==>SetListView
Func GetIfEntry($ifIndex)
Local $tagBuffer, $tBuffer, $pBuffer, $iResult, $iSpeed, $sDescr
$tagBuffer = "wchar[256];dword[5];byte[8];dword[16];char[256]"
$tBuffer = DllStructCreate($tagBuffer)
$pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, 2, $ifIndex, 1)
$iResult = DllCall("iphlpapi.dll", "long", "GetIfEntry", "ptr", $pBuffer)
$iSpeed = DllStructGetData($tBuffer, 2, 4) / 1000 / 1000
$sDescr = DllStructGetData($tBuffer, 5)
$tBuffer = 0
Return SetError($iResult[0], $iSpeed, $iSpeed)
EndFunc ;==>GetIfEntry
Func _GetAdaptersInfo()
Local $iResult, $tBuffer, $pBuffer, $aResult[1][9], $tagADPTINFO, $tAdpt
; 第一次调用传递空值,pOutBufLen ( $iResult[2] ) 设为结构所需大小,单位byte。
$iResult = DllCall("iphlpapi.dll", "dword", "GetAdaptersInfo", "ptr", 0, "ulong*", 0)
$tBuffer = DllStructCreate("byte[" & $iResult[2] & "]") ; 定义$iResult[2] 字节的缓存区域 (分配内存空间)。
$pBuffer = DllStructGetPtr($tBuffer) ; 获取内存指针。
; 第二次调用,GetAdaptersInfo把网卡信息复制到指定的内存空间 ($tBuffer) 中。
$iResult = DllCall("iphlpapi.dll", "dword", "GetAdaptersInfo", "ptr", $pBuffer, "ulong*", $iResult[2])
; $iResult[0]值为0则调用成功,否则为系统错误号。
; 数据转换, byte --> IP_ADAPTER_INFO
$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"
While $pBuffer
$tAdpt = DllStructCreate($tagADPTINFO, $pBuffer)
$aResult[0][0] += 1
ReDim $aResult[$aResult[0][0] + 1][9]
$aResult[$aResult[0][0]][0] = DllStructGetData($tAdpt, "AdptName") ; 网卡名称
$aResult[$aResult[0][0]][1] = DllStructGetData($tAdpt, "AdptDescr") ; 网卡描述
$aResult[$aResult[0][0]][2] = DllStructGetData($tAdpt, "MacAddr") ; 网卡MAC
$aResult[$aResult[0][0]][3] = DllStructGetData($tAdpt, "Index") ; 网卡索引号
$aResult[$aResult[0][0]][4] = DllStructGetData($tAdpt, "Type") ; 类型
$aResult[$aResult[0][0]][5] = DllStructGetData($tAdpt, "DhcpEnabled") ; DHCP是否启用 true = 启用, false = 禁用
$aResult[$aResult[0][0]][6] = DllStructGetData($tAdpt, "IpAddr") ; IP 地址
$aResult[$aResult[0][0]][7] = DllStructGetData($tAdpt, "GatewayAddr") ; 网关地址
$aResult[$aResult[0][0]][8] = DllStructGetData($tAdpt, "DhcpAddr") ; DHCP地址, 只有DhcpEnabled为true时,此值才有效。
$pBuffer = DllStructGetData($tAdpt, "NextAdpt") ; [下一张网卡信息的内存地址。]
$tAdpt = 0
WEnd
$tBuffer = 0
Return SetError($iResult[0], 0, $aResult)
EndFunc ;==>_GetAdaptersInfo
|