简体   繁体   中英

Getting Adapter bandwidth and Available IP Addresses

Can anybody tell me how can I get the available bandwidth and the ip addresses present in the network adapter. First I will tell what I have done. I tried with the Windows Management Instrumentation (WMI) queries of the classes Win32_PerfFormattedData and Win32_PerfFormattedData_Tcpip_NetworkInterface . Win32_PerfFormattedData - from this class I can able to get the current bandwidth of the adapter. Win32_PerfFormattedData_Tcpip_NetworkInterface - From this class I can able to get the ip addresses present in the adapter. The problem is, I dont know how to find the relation between the two If I have more than one network adapter in the system as I dont find any common properties between these two classes properties. Please help me to resolve this problem. Suggestions are welcome If there is any other way of getting the current bandwidth and the Ip addresses of the network adapter.

Use Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration instead. Here the simple PowerShell script example:

$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
}

On Windows 8 and later you should use MSFT_NetAdapter class instead of Win32_NetworkAdapter . Also Win32_NetworkAdapterConfiguration returns only IPv4 configuration data. See this for the additional info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM