> new to Perl, have need to fetch MAC address from local 
> machine.  Can anyone 
> provide a code snippet to get me pointing in the correct direction???

As always, the WMI is your friend (assuming you are on Windows 2000 or
above). Substitute any other fqdn for $ENV{COMPUTERNAME}, assuming you
have admin rights on it. Sorry in advance if this wraps...

More docs here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/
wmi/win32_networkadapterconfiguration.asp

Cheers,
Paul



use Win32::OLE;

print <<BLA;
NicID  DHCP? IP Addresses           MAC                 DNS Servers
========================================================================
======================
BLA

my $format = <<FORMAT;
@<<<   @<<<  @<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<
@<<<<<<<<<<<<<<<<<<<<<<<<<<<
FORMAT

my $x =
Win32::OLE->GetObject("WinMgmts://$ENV{COMPUTERNAME}/root/cimv2") or die
"Cannot instantiate WMI";
my $y = $x->ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE
AdapterType = \"Ethernet 802.3\"");
foreach my $adapter (in $y) {
        my $settings =
$adapter->Associators_(undef,"Win32_NetworkAdapterConfiguration");
        my $adaptername = $adapter->{Index};
        my @addresses;
        foreach my $setting (in $settings) {
                next unless $setting->{IPAddress}->[0];
                my $enabled = $setting->{DHCPEnabled} ? "Yes" : "No";
                my $addresses =  join(", ", @{$setting->{IPAddress}});
                my $dnsservers = join(", ",
@{$setting->{DNSServerSearchOrder}});
                my $macaddress = $setting->{MACAddress};
                push @addresses, [$enabled, $addresses, $macaddress,
$dnsservers];
        }
        foreach my $address (@addresses) { print swrite($format,
$adaptername, $address->[0], $address->[1], $address->[2],
$address->[3]) }
}

sub swrite {
        die "usage: swrite PICTURE ARGS" unless @_;
        my $format = shift;
        $^A = "";
        formline($format,@_);
        return $^A;
}

*****************************************************************
Gloucester Research Limited believes the information 
provided herein is reliable. While every care has been 
taken to ensure accuracy, the information is furnished 
to the recipients with no warranty as to the completeness 
and accuracy of its contents and on condition that any 
errors or omissions shall not be made the basis for any 
claim, demand or cause for action.
*****************************************************************


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to