2016-11-14 28 views
0

任何人都可以告訴我如何獲取網絡適配器中的可用帶寬和IP地址。 首先我會告訴我做了什麼。我試着用Windows Management Instrumentation(WMI)查詢類Win32_PerfFormattedDataWin32_PerfFormattedData_Tcpip_NetworkInterfaceWin32_PerfFormattedData - 從這個類我可以獲得適配器的當前帶寬。 Win32_PerfFormattedData_Tcpip_NetworkInterface - 從這個類中,我可以獲得適配器中的IP地址。 問題是,我不知道如何找到兩者之間的關係如果我有多個網絡適配器在系統中,因爲我沒有找到這兩個類屬性之間的任何共同屬性。請幫我解決這個問題。歡迎提出建議如果有任何其他方式獲取當前帶寬和網絡適配器的IP地址。獲取適配器帶寬和可用IP地址

回答

0

改爲使用Win32_NetworkAdapterWin32_NetworkAdapterConfiguration。這裏簡單的PowerShell腳本例子:

$objWMi = get-wmiobject -Query "Select * from Win32_NetworkAdapter where PhysicalAdapter = True" 

foreach ($obj in $objWmi) 
{ 
    write-host "AdapterType:" $obj.AdapterType 
    write-host "Caption:" $obj.Caption 
    write-host "CommunicationStatus:" $obj.CommunicationStatus 
    write-host "Description:" $obj.Description 
    write-host "DeviceName:" $obj.DeviceName 
    write-host "MACAddress:" $obj.MACAddress 
    write-host "Speed:" $obj.Speed 
    write-host "Name:" $obj.Name 

    $config = get-wmiobject -Query "select * from Win32_NetworkAdapterConfiguration where InterfaceIndex = $($obj.InterfaceIndex)" 
    foreach($data in $config) 
    { 
     write-host "NetworkAddress:" $config.IPAddress 
    } 

    write-host 
    write-host "########" 
    write-host 
} 

在Windows 8和更高版本,你應該使用的Win32_NetworkAdapterMSFT_NetAdapter類代替。另外Win32_NetworkAdapterConfiguration只返回IPv4配置數據。請參閱this瞭解更多信息。

+0

非常感謝 –