Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: obtaining MAC address(es)

by saucepan (Scribe)
on Jan 26, 2001 at 02:28 UTC ( #54392=note: print w/replies, xml ) Need Help??

in reply to obtaining MAC address(es)

Tricky one! I tried having a peek at my (FreeBSD) ifconfig sources to see what it might be up to, but found it impenetrable to casual inspection by someone with my modest C skills. :(

The most portable method I could come up with is, unfortunately:

sub unique { keys %{{ map { $_, 1 } @_ }} } my $ifconfig; -x and $ifconfig = $_, last for qw(/sbin/ifconfig /bin/ifconfig); die "Can't find ifconfig\n" unless $ifconfig; my @hwaddrs = `$ifconfig` =~ /\b((?:[a-f\d]{2}:){5}[a-f\d]{2})\b/gi; { local ($\, $,) = ("\n", "\n") and print unique @hwaddrs }
..and this will only work on a Unix system that uses ifconfig (and possibly only on Linux and FreeBSD, on which I was able to test).

Hopefully this could serve as a start if you decide to do as Fastolfe suggested and write a module that provides this service portably. :)

If what you are actually looking for is a host-unique ID of some kind, you might be able to get away with using the host's default IP address as the ID, depending on the extent of your persistence (DHCP), global uniqueness (RFC 1918) and security requirements.

update: minor cleanup of ugly regex
update: my a-f got changed to a-z somewhere along the line (fixed)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://54392]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2023-03-23 03:49 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.