OK. Спасибо за публикацию короткого сценария. Пока вы работали над этим, я следовал по другой дорожке, используя 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;
}
}
Выход:
=== From Win32_NetworkAdapter ===
Name: Intel(R) PRO/Wireless 3945ABG Network Connection
Canonical name: Intel_R__PRO_Wireless_3945ABG_Network_Connection
=== From Win32_PerfRawData_Tcpip_NetworkInterface ===
Name: Intel[R] PRO_Wireless 3945ABG Network Connection - Packet Scheduler Miniport
Canonical name: Intel_R__PRO_Wireless_3945ABG_Network_Connection___Packet_Scheduler_Miniport
54000000