- 论坛徽章:
- 0
|
回复 #1 mouse.rice 的帖子
Hello,
under Windows you can use Win32 modules to access information
about MAC address.
Sample code:
- use strict;
- use warnings;
- use Win32::OLE qw(in);
- use Win32::OLE::Variant;
- my $wmi_object ='winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2';
- my $objWMIService = Win32::OLE->GetObject($wmi_object);
- my $wql = 'SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True';
- my $nics = $objWMIService->ExecQuery($wql);
- my $cnt = 1;
- print "=" x 60, "\n";
- foreach my $nic (in $nics) {
- print "Network Interface Card: $cnt\n";
- print ' Description: ' . $nic->Description, "\n";
- print ' Physical (MAC) address: ' . $nic->MACAddress, "\n";
- print ' Host name: ' . $nic->DNSHostName, "\n";
- # display all IP addresses configured for this adapter
- if (!!($nic->IPAddress)) {
- for my $x (0 .. $#{$nic->IPAddress}) {
- print ' IP address: ' . $nic->IPAddress($x), "\n";
- }
- }
- if (!!($nic->IPSubnet)) {
- for my $x (0 .. $#{$nic->IPSubnet}) {
- print ' Subnet: ' . $nic->IPSubnet($x), "\n";
- }
- }
- if (!!($nic->DefaultIPGateway)) {
- for my $x (0 .. $#{$nic->DefaultIPGateway}) {
- print ' Default gateway: ' . $nic->DefaultIPGateway($x), "\n";
- }
- }
- $cnt++;
- print "=" x 60, "\n";
- }
复制代码 |
|