Link to home
Start Free TrialLog in
Avatar of Dirk Kotte
Dirk KotteFlag for Germany

asked on

Need support creating a perl script selecting MAC-Adresses

Hi,
i need ideas (or a script) how to search all MAC Addresses of a windows system and pass these as parameter to an external program...with PERL.

script should do the following:
1. get all MAC-Adresses (LAN1, LAN2, WLAN,...)
      = AA-AA-AA-AA-AA-AA , BB-BB-BB-BB-BB-BB , CC-CC-CC-CC-CC-CC-CC

2. start external programm and pass every MAC (one after another) ... possible within a loop
extProg.exe AA-AA-AA-AA-AA-AA
extProg.exe BB-BB-BB-BB-BB-BB
extProg.exe CC-CC-CC-CC-CC-CC-CC
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perl is my preferred language but it's not always the best choice.  In this case, I'd use a cleaner/shorter powershell script.

$interfaces = Get-WmiObject -Class 'Win32_NetworkAdapterConfiguration'
Foreach ($interface in $interfaces) { Write-Output $interface.MACaddress }

Open in new window


PS C:\test> .\get_mac.ps1
00:1C:C0:A3:6E:0A
20:41:53:59:4E:FF
00:15:17:F8:6C:2A

That example uses Write-Output to print the mac addresses, but you can just as easily execute your external command.  Just like in Perl, powershell has several ways to execute external connamds.

Another advantage in using the powershell script is that it can find more mac addresses than the getmac command.  On my system the getmac command found 2 mac addresses and the powershell script found 3.

Here's what I get from David's script.

c:\test>get_mac.pl
Use of uninitialized value $mac in pattern match (m//) at C:\test\get_mac.pl line 19.
00-1C-C0-A3-6E-0A
00-15-17-F8-6C-2A
Avatar of Dirk Kotte

ASKER

Try this from yesterday to now ... works great and independent from windows version.
thanks.