NAME
OIE::Utils::MAC - Handles hardware MAC Addresses (EUI-48 and EUI-64)
SYNOPSIS
use OIE::Utils::MAC;
my $mac = OIE::Utils::MAC->new( '00:11:22:aa:bb:cc' );
my $mac = OIE::Utils::MAC->new( mac => '0011.22AA.BBCC' );
print "MAC provided at object creation was: ", $mac->original;
print "EUI48\n" if $mac->is_eui48;
print "EUI64\n" if $mac->is_eui64;
print "Unicast\n" if $mac->is_unicast;
print "Multicast\n" if $mac->is_multicast;
print "Locally Administerd\n" if $mac->is_local;
print "Universally Administered\n" if $mac->is_universal;
print 'Basic Format: ',$mac->as_basic,"\n";
print 'Bpr Format: ',$mac->as_bpr,"\n";
print 'Cisco Format: '$mac->as_cisco,"\n";
print 'IEEE Format: '$mac->as_ieee,"\n";
print 'Microsoft Format: ',$mac->as_microsoft,"\n";
print 'Sun Format: ',$mac->as_sun,"\n";
use OIE::Utils::MAC qw( :all );
my $mac = q/00.11.22.33.44.55/;
print "EUI48\n" if mac_is_eui48($mac);
print "EUI64\n" if mac_is_eui64($mac);
print "Unicast\n" if mac_is_unicast($mac);
print "Multicast\n" if mac_is_multicast($mac);
print "Locally Administerd\n" if mac_is_local($mac);
print "Universally Administered\n" if mac_is_universal($mac);
print 'Basic Format: ',mac_as_basic($mac),"\n";
print 'Bpr Format: ',mac_as_bpr($mac),"\n";
print 'Cisco Format: 'mac_as_cisco($mac),"\n";
print 'IEEE Format: 'mac_as_ieee($mac),"\n";
print 'Microsoft Format: ',mac_as_microsoft($mac),"\n";
print 'Sun Format: ',mac_as_sun($mac),"\n";
DESCRIPTION
This module provides an interface to deal with Media Access Control (or MAC) addresses. These are the addresses that uniquely identify a device on a layer 2 network. Although the common case is hardware addresses on Ethernet network cards, there are a variety of devices that use this system. This module supports both EUI-48 and EUI-64 addresses and implements an OO and a functional interface.
Some devices that use EUI-48 (or MAC-48) addresses include:
Ethernet
802.11 wireless networks
Bluetooth
IEEE 802.5 token ring
FDDI
ATM
Some devices that use EUI-64 addresses include:
Firewire
IPv6
ZigBee / 802.15.4 wireless personal-area networks
OO METHODS
OIE::Utils::MAC->new( mac => $mac )
Creates and returns a new OIE::Utils::MAC object. The MAC value is required.
OIE::Utils::MAC->new( $mac )
Simplified creation method
OO METHODS
original
returns the original mac string as used when creating the MAC object
OO PROPERTY METHODS
is_eui48
returns true if mac address is determined to be of the EUI48 standard
is_eui64
returns true if mac address is determined to be of the EUI64 standard
is_multicast
returns true if mac address is determined to be a multicast address
is_unicast
returns true if mac address is determined to be a unicast address
is_local
returns true if mac address is determined to be locally administered
is_universal
returns true if mac address is determined to be universally administered
OO NORMALIZATION METHODS
as_basic
returns the mac address normalized as a hexidecimal string that is 0 padded and without delimiters
001122aabbcc
as_bpr
returns the mac address normalized as a hexidecimal string that is 0 padded with : delimiters and with 1,length leading where length is the number of hex pairs (ie 6 for EUI48)
1,6,00:11:22:aa:bb:cc
as_cisco
returns the mac address normalized as a hexidecimal string that is 0 padded and with . delimiting every 2nd octet (ie after every 4th character)
0011.22aa.bbcc
as_ieee
returns the mac address normalized as a hexidecimal string that is 0 padded and with - delimiting every octet (ie after every 2nd character)
00-34-56-78-9a-bc
as_ipv6_suffix
returns the EUI-64 address in the format used for an IPv6 autoconf address suffix
as_microsoft
returns the mac address normalized as a hexidecimal string that is 0 padded and with : delimiting every octet (ie after every 2nd character)
00:34:56:78:9a:bc
as_sun
returns the mac address normalized as a hexidecimal string that is not padded and with - delimiting every octet (ie after every 2nd character)
0-34-56-78-9a-bc
as_tokenring
returns the mac address normalized as a hexidecimal string that is 0 padded and with - delimiting every octet (ie after every 2nd character) and each octect is bit-reversed order
00-2d-6a-1e-59-3d
to_eui48
converts to EUI-48 (if the eui-64 was derived from eui-48)
to_eui64
converts to EUI-64
STAND ALONE PROPERTY FUNCTIONS
mac_is_eui48($mac)
returns true if mac address in $mac is determined to be of the EUI48 standard
mac_is_eui64($mac)
returns true if mac address in $mac is determined to be of the EUI64 standard
mac_is_multicast($mac)
returns true if mac address in $mac is determined to be a multicast address
mac_is_unicast($mac)
returns true if mac address in $mac is determined to be a unicast address
mac_is_local($mac)
returns true if mac address in $mac is determined to be locally administered
mac_is_universal($mac)
returns true if mac address in $mac is determined to be universally administered
STAND ALONE NORMALIZATION METHODS
mac_as_basic($mac)
returns the mac address in $mac normalized as a hexidecimal string that is 0 padded and without delimiters
001122aabbcc
mac_as_bpr($mac)
returns the mac address in $mac normalized as a hexidecimal string that is 0 padded, with : delimiting and 1,length leading. length is the number of hex pairs (6 for EUI48)
1,6,00:11:22:aa:bb:cc
mac_as_cisco($mac)
returns the mac address in $mac normalized as a hexidecimal string that is 0 padded and with . delimiting every 2nd octet (ie after every 4th character)
0011.22aa.bbcc
mac_as_ieee($mac)
returns the mac address in $mac normalized as a hexidecimal string that is 0 padded and with - delimiting every octet (ie after every 2nd character)
00-34-56-78-9a-bc
mac_as_ipv6_suffix($mac)
returns the mac address in $mac in the format used for an IPv6 autoconf address suffix
will convert from eui48 or eui64 if needed
mac_as_microsoft($mac)
returns the mac address in $mac normalized as a hexidecimal string that is 0 padded and with : delimiting every octet (ie after every 2nd character)
00:34:56:78:9a:bc
mac_as_sun($mac)
returns the mac address in $mac normalized as a hexidecimal string that is not padded and with - delimiting every octet (ie after every 2nd character)
0-34-56-78-9a-bc
mac_as_tokenring($mac)
returns the mac address in $mac normalized as a hexidecimal string that is 0 padded and with - delimiting every octet (ie after every 2nd character) and each octect is bit-reversed order
00-2d-6a-1e-59-3d
CREDITS
Myself, Dean Hamstead <dean.hamstead@fragfest.com.au>
Stolen lots of ideas and some pod content from Device::MAC and Net::MAC.
Various contributers thanks to GitHub
DEVELOPMENT
Please fork this and send me pull requests! https://github.com/djzort/Perl-NetAddr-MAC
TODO
- tests!
- as_tokenring - need to find a nifty way to reverse the bit order
COPYRIGHT
Copyright (c) 2011, Dean Hamstead
LICENSE
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.