note
saucepan
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. :( <p>
The most portable method I could come up with
is, unfortunately:<p>
<code>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 }
</code>
..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).<p>
Hopefully this could serve as a start if you decide to
do as [id://54375|Fastolfe suggested] and write a module that provides
this service portably. :)<p>
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 [id://44734|default IP address]
as the ID, depending on the extent of your persistence (DHCP), global uniqueness
(<a href="http://andrew2.andrew.cmu.edu/rfc/rfc1918.html">RFC
1918</a>) and security requirements.<p>
<font size=-1><b>update</b>: minor cleanup of ugly regex<br>
<b>update</b>: my a-f got changed to a-z somewhere along the
line (fixed)</font>
54362
54362