获取适配器带宽和可用IP地址

Getting Adapter bandwidth and Available IP Addresses

本文关键字:IP 地址 适配器 带宽 获取      更新时间:2023-10-16

谁能告诉我如何才能获得网络适配器中的可用带宽和ip地址?首先我要告诉你我做了什么。我尝试了Windows管理工具(WMI)类的查询Win32_PerfFormattedDataWin32_PerfFormattedData_Tcpip_NetworkInterfaceWin32_PerfFormattedData -从这个类我可以得到适配器的当前带宽。Win32_PerfFormattedData_Tcpip_NetworkInterface -从这个类中,我可以获得适配器中存在的ip地址。问题是,我不知道如何找到两者之间的关系,如果我在系统中有一个以上的网络适配器,因为我找不到这两个类属性之间的任何共同属性。请帮我解决这个问题。如果有任何其他方法获得当前带宽和网络适配器的Ip地址,欢迎提出建议。

使用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及以后,你应该使用MSFT_NetAdapter类而不是Win32_NetworkAdapterWin32_NetworkAdapterConfiguration也只返回IPv4配置数据。