获取链接速度 – Win32_PerfRawData_Tcpip_NetworkInterface

我发现确定networking连接的链接速度 ,现在我试图关联从Win32_PerfRawData_Tcpip_NetworkInterfaceWin32_NetworkAdapter (或Win32_NetworkAdapterConfiguration )的数据。

在类Win32_PerfRawData_Tcpip_NetworkInterface我看不到任何索引或唯一键,我可以用它来引用Win32_NetworkAdapterConfigurationWin32_NetworkAdapter. I tried to use the Win32_NetworkAdapter. I tried to use the Win32_PerfRawData_Tcpip_NetworkInterface and Win32_NetworkAdapter中Win32_NetworkAdapter. I tried to use the名称,但它们看起来不一样。

例如

名称:英特尔(R)PRO / 1000 PLnetworking连接

VS

名称:英特尔(R)PRO_1000 PLnetworking连接

任何提示?

先谢谢你,

Milde

===

也许这段代码将帮助你帮助我:)

 # I got the DeviceID of a NIC and use it to get the "NetConnection ID": $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "Exit: WMI connection failed. \n"; $colNicSetts = $objWMIService->ExecQuery( "SELECT * FROM Win32_NetworkAdapter Where DeviceID = '$ID'", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $colNicSetts){ $NetConnID = $objItem->{NetConnectionID}; } # => $NetConnID stores "Intel(R) PRO/1000 PL Network Connection". # Now I tried to get the Link Speed with sth. like that: $collItems = $objWMIService->ExecQuery( "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '$NetConnID'", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); foreach my $objItem (in $collItems){ $LinkSpeed = $objItem->{CurrentBandwidth}; } # "Win32_PerfRawData_Tcpip_NetworkInterface" contains "Intel[R] PRO_1000 PL Network" Connection # "Intel(R) PRO/1000 PL Network Connection" != Intel[R] PRO_1000 PL Network Connection # => $LinkSpeed empty 

Solutions Collecting From Web of "获取链接速度 – Win32_PerfRawData_Tcpip_NetworkInterface"

好。 感谢张贴短脚本。 当您正在处理这个问题时,我正在使用DBD :: WMI跟踪一个不同的轨道,并通过文档挖掘,看看您是否错过了任何东西。

我找不到一个更好的方式(必须有一个)而不是规范化名称:

 #!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; my $computer = '.'; ($computer) = @ARGV if @ARGV; my $dbh = DBI->connect("dbi:WMI:$computer", undef, undef, { RaiseError => 1}, ); print "=== From Win32_NetworkAdapter ===\n"; my $name = $dbh->selectall_arrayref( 'SELECT * FROM Win32_NetworkAdapter WHERE DeviceID = 11' )->[0]->[0]->{Name}; (my $canonname = $name) =~ s/[^A-Za-z0-9]/_/g; print "Name: $name\nCanonical name: $canonname\n\n"; my $sth = $dbh->prepare( 'SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface' ); $sth->execute; print "=== From Win32_PerfRawData_Tcpip_NetworkInterface ===\n"; while (defined (my $adapter = $sth->fetchrow_arrayref )) { my $conf = $adapter->[0]; my $perfname = $conf->{Name}; (my $canonperfname = $perfname) =~ s/[^A-Za-z0-9]/_/g; if ( $canonperfname =~ /^$canonname/ ) { print "Name: $perfname\nCanonical name: $canonperfname\n"; print $conf->{CurrentBandwidth}, "\n\n"; last; } } 

输出:

 ===从Win32_NetworkAdapter ===
名称:英特尔(R)PRO /无线3945ABG网络连接
规范名称:Intel_R__PRO_Wireless_3945ABG_Network_Connection

 ===从Win32_PerfRawData_Tcpip_NetworkInterface ===
名称:英特尔[R] PRO_Wireless 3945ABG网络连接 - 数据包计划程序微型端口
规范名称:Intel_R__PRO_Wireless_3945ABG_Network_Connection___Packet_Scheduler_Miniport
 5400

我只是用WMI-Tools看我的机器,因为我认为它一定很容易… 😉
但不是…

但是我在我的机器上发现,“Win32_NetworkAdapter.Name”+“__”+“Win32_NetworkAdapter.InterfaceIndex”的结果在“Win32_PerfFormattedData_Tcpip_NetworkInterface.Name =”NVIDIA nForce网络控制器_2中。 ]。

来自我的机器的示例:

 Win32_NetworkAdapter.DeviceID = “13”
 Win32_NetworkAdapter.NetConnectionID =“本地连接2”
 Win32_NetworkAdapter.InterfaceIndex = “2”
 Win32_NetworkAdapter.Name =“NVIDIA nForce网络控制器”
 Win32_PerfFormattedData_Tcpip_NetworkInterface =“NVIDIA nForce网络控制器_2”

我希望,我已经理解你的问题了,这可能有帮助?!

BR – mabra

我能找到的唯一方法是使用Win32_PnPEntity类获取网络适配器的DeviceName,然后将其转换为InstanceName 。 这使您可以找到一个可用于其他WMI表的键值(我使用InterfaceIndex,但在Win32_NetworkAdapter类中还有其他选择。

所以在高层次上:

  1. 获取Win32_NetworkAdapter的一个实例
  2. 使用以下两个WMI WQL查询之一来获取PnPEntity
  3. 通过替换将Win32_PNPEntity.Name转换为InstanceName:
    1. (与[
    2. )与]
    3. #\ /所有与_
  4. 使用该InstanceName来查询Win32_PerfFormattedData_Tcpip_NetworkInterface

这是相当复杂的,但是因为InstanceName是从PnPEntity Name中衍生出来的,所以这是唯一能找到准确映射的方法。

以下是我能够获得NetworkAdapter的PnPEntity实例的两种方法:

 ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID='12'} WHERE ResultClass=Win32_PnPEntity SELECT * FROM Win32_PNPEntity where DeviceID='PCI\\VEN_14E4&DEV_1684&SUBSYS_1309103C&REV_10\\4&11050A08&0&00E5'