Commit af479a82 authored by Leigh B Stoller's avatar Leigh B Stoller

Add GenFakeMac() to generate random mac address.

parent 081be6ca
......@@ -30,6 +30,7 @@ use Exporter;
@EXPORT = qw( ipToMac macAddSep fatal mysystem mysystem2
findDNS setState isRoutable findDomain convertToMebi
ipToNetwork CIDRmask untaintNumber untaintHostname
GenFakeMac
);
use libtmcc;
......@@ -278,5 +279,30 @@ sub mysystem2($)
}
}
#
# Generate a hopefully unique mac address that is suitable for use
# on a shared node where uniqueness matters.
#
sub GenFakeMac()
{
my $mac;
#
# Random number for lower 4 octets.
#
my $ran=`/bin/dd if=/dev/urandom count=32 bs=1 2>/dev/null | /usr/bin/sha256sum`;
return undef
if ($?);
if ($ran =~ /^\w\w\w(\w\w\w\w\w\w\w\w\w\w)/) {
$mac = $1;
}
#
# Set the "locally administered" bit, good practice.
#
return "02" . $mac;
}
# Must be last thing in file.
1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment