如何通过api获取网卡的线路速度?
如图,看最近需要检测网络链路速度的工具比较多,想自己琢磨做个。 Func _EnumIfEntries()
Local $iResult, $tBuffer, $pBuffer, $tIfEntry, $tCount, $aResult
$iResult = DllCall("iphlpapi.dll", "dword", "GetIfTable", "ptr", 0, "ulong*", 0, "int", 1)
$tBuffer = DllStructCreate("ubyte Binary[" & $iResult & "]")
$pBuffer = DllStructGetPtr($tBuffer, "Binary")
$iResult = DllCall("iphlpapi.dll", "dword", "GetIfTable", "ptr", $pBuffer, _
"ulong*", $iResult, "int", 1)
$tCount = DllStructCreate("ulong NumberofEntries", $pBuffer)
$aResult = DllStructGetData($tCount, "NumberofEntries")
Redim $aResult[$aResult + 1]
$pBuffer += 4
For $i = 1 To $aResult
$tIfEntry = DllStructCreate($tagMIB_IFROW, $pBuffer)
$pBuffer += DllStructGetSize($tIfEntry)
$aResult[$i] = DllStructGetData($tIfEntry, "Name")
$aResult[$i] = DllStructGetData($tIfEntry, "Descr")
$aResult[$i] = DllStructGetData($tIfEntry, "Index")
$aResult[$i] = DllStructGetData($tIfEntry, "Type")
$aResult[$i] = DllStructGetData($tIfEntry, "Speed")
$aResult[$i] = DllStructGetData($tIfEntry, "PhysicalAddr")
$aResult[$i] = DllStructGetData($tIfEntry, "AdminStatus")
$aResult[$i] = DllStructGetData($tIfEntry, "OperStatus")
$aResult[$i] = DllStructGetData($tIfEntry, "InOctets")
$aResult[$i] = DllStructGetData($tIfEntry, "OutOctets")
$tIfEntry = 0
Next
$tBuffer = 0
Return SetError($iResult, 0, $aResult)
EndFunc ;==>_EnumIfEntries
$aResult[$i] = DllStructGetData($tIfEntry, "Speed") 这个就是网卡速度,你多在论坛搜索一下,有这方面的资料! 回复 2# penguinl
哦?朋友,您是在哪里看到这个函数的?能否发个连接? 搜了搜网卡、速度、线路速度、链路速度、还有几个api函数名,就找到一个P版的GetAdaptersInfo,而且GetAdaptersInfo还无法获取到当前网卡工作速率。 通过msdn官方找了下资料,用字符串声明$tagMIB_IFROW时,只能写到获取网卡物理地址的地方,再往下返回值就各种变了,在我本机能获取到无线网卡的线路速度,但是移植到其他电脑就无法正确获取了。
页:
[1]