【问题标题】:Getting Adapter bandwidth and Available IP Addresses获取适配器带宽和可用 IP 地址
【发布时间】:2016-11-14 04:10:06
【问题描述】:

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

【问题讨论】:

    标签: c++ wmi wmi-query


    【解决方案1】:

    请改用Win32_NetworkAdapter 和Win32_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_NetworkAdapter。此外,Win32_NetworkAdapterConfiguration 仅返回 IPv4 配置数据。有关更多信息,请参阅 this。

    【讨论】:

    • 非常感谢
    猜你喜欢
    • 2012-10-21
    • 2023-04-08
    • 1970-01-01
    • 2022-03-03
    • 2018-01-26
    • 1970-01-01
    • 2014-07-03
    • 2020-06-24
    • 2015-01-16
    相关资源
    最近更新 更多