Converts a Token-Ring MAC-Address into an Ethernet MAC-Address and vise versa.
Demonstrates the usage of hashes.
Author: G. Lange, glange@libero.it
#!usr/bin/perl -w
# Converts a Token-Ring MAC-Address into
# an Ethernet and vise versa.
# Hashes
# MAC-Address Format: 00-30-F5-07-5D-7D
$0 =~ s|^.*[\\/]||;
$usage="Usage: $0 <mac-address>\nFormat of the mac-address: xx-xx-xx-x
+x-xx-xx\n";
if ($ARGV[0] eq "") { print $usage; exit; }
%convert = (
"0" => "0",
"1" => "8",
"2" => "4",
"3" => "C",
"4" => "2",
"5" => "A",
"6" => "6",
"7" => "E",
"8" => "1",
"9" => "9",
"A" => "5",
"B" => "D",
"C" => "3",
"D" => "B",
"E" => "7",
"F" => "F",
);
$mac = $ARGV[0];
@mac_array = split( /\-/ , $mac);
foreach $a (0 .. $#mac_array) {
$c_mac[$a] = $convert{substr(uc($mac_array[$a]),1,1)}
. $convert{substr(uc($mac_array[$a]),0,1)};
# if ($a < ($#mac_array)) { $c_mac[$a].= "-"; }
}
$mac = join("-", @c_mac);
print $mac;