Perl Function: mac2char

Function to convert a mac to a 6 byte string. Warning: it's nor a printable string.

sub mac2char() { my $mac = shift(); if ($mac !~ /w[-:]w[-:]w[-:]w[-:]w[-:]w/) { print "n$mac not a valid mac addressn"; return 0; } my @chars = split(/[:-]/,$mac); my $ret; foreach (@chars) { $ret .= chr(hex($_)); } return $ret; } sub char2mac() { my $chars = shift(); my $sep = shift(); my (@ret,$ret,$i); $sep ||= ":"; for ($i=0;$i<6;$i++) { my $char = substr($chars,$i,1); $octet = sprintf("%x",(ord($char))); $octet = &zeropad($octet); push(@ret,$octet); #push(@ret,$char); } return join($sep,@ret); }

Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
Logged IP:
To prevent spam please submit by clicking the kitten: