Warning: Undefined array key "action" in /home/bakers/html/entryreply.php on line 5

Warning: Undefined variable $output in /home/bakers/html/entryreply.php on line 50

Warning: Undefined array key "EntrySubject" in /home/bakers/html/entryreply.php on line 51

Warning: Undefined variable $logintext in /home/bakers/html/entryreply.php on line 97

Warning: Undefined variable $reply_name in /home/bakers/html/entryreply.php on line 103

Warning: Undefined variable $reply_email in /home/bakers/html/entryreply.php on line 104
Perturb.org - interesting technology related things from around the internet

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: 3.227.235.216
To prevent spam please submit by clicking the kitten: