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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.