X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=data%2FPVE%2FTools.pm;h=5e8e7bf46460c1abfa5fd199e3bcca14c5176cbe;hp=d80524013b040b3f0e2b1acdc028a4191484ed2f;hb=a413a515c5937862029c30c5171b935e3abd6824;hpb=67799787db420843a67d60b334944f4c308287d3 diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index d805240..5e8e7bf 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -12,6 +12,7 @@ use Fcntl qw(:DEFAULT :flock); use base 'Exporter'; use URI::Escape; use Encode; +use Digest::SHA1; our @EXPORT_OK = qw( lock_file @@ -635,5 +636,27 @@ sub decode_text { return Encode::decode("utf8", uri_unescape($data)); } +sub random_ether_addr { + + my $rand = Digest::SHA1::sha1_hex(rand(), time()); + + my $mac = ''; + for (my $i = 0; $i < 6; $i++) { + my $ss = hex(substr($rand, $i*2, 2)); + if (!$i) { + $ss &= 0xfe; # clear multicast + $ss |= 2; # set local id + } + $ss = sprintf("%02X", $ss); + + if (!$i) { + $mac .= "$ss"; + } else { + $mac .= ":$ss"; + } + } + + return $mac; +} 1;