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)


In reply to Re: obtaining MAC address(es) by saucepan
in thread obtaining MAC address(es) by dshahin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.