bb.net
Class EthernetMacAddress

java.lang.Object
  extended by bb.net.EthernetMacAddress

public class EthernetMacAddress
extends Object

This class stores an ethernet MAC (hardware) address as a byte[].

To get a machine's Ethernet MAC (Hardware) Address using DOS (is unix similar?):

        1) from a command line, ping the target machine; for example:
                ping 192.168.1.101
        (So, you need to know the target machine's hostname or ip address before can do this.)

        2) then execute
                arp -a
        on the command line to list the ip-->mac address table; for example, should see output like
                Interface: 192.168.1.100 --- 0x2
                  Internet Address      Physical Address      Type
                  192.168.1.101         00-03-47-73-dd-a5     dynamic
 

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer
See Also:
TCP/IP tutorial, How do I find my MAC Address?

Nested Class Summary
static class EthernetMacAddress.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private  byte[] bytes
          Array of 6 bytes which stores the 48 bit ethernet MAC address.
static char byteSeparatorChar
          Preferred char used to separate the bytes in an ethernet MAC address's String representation.
 
Constructor Summary
EthernetMacAddress(String address)
          Constructor which parse the bytes from a String valued address.
 
Method Summary
static String byteToString(byte b)
           
 byte[] getBytes()
          Returns a clone of the internal byte[] (to maintain encapsulation).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

byteSeparatorChar

public static final char byteSeparatorChar
Preferred char used to separate the bytes in an ethernet MAC address's String representation.

There appear to be 2 conventions: a dash (i.e. '-') or a colon (i.e. ':') char. The value of this constant is a dash (i.e. '-'), because that is what Windows uses.

See Also:
Constant Field Values

bytes

private final byte[] bytes
Array of 6 bytes which stores the 48 bit ethernet MAC address.

Constructor Detail

EthernetMacAddress

public EthernetMacAddress(String address)
                   throws IllegalArgumentException,
                          NumberFormatException
Constructor which parse the bytes from a String valued address. Each byte in address must be in hexadecimal format, and must be separated by either a '-' or ':' char.

Throws:
IllegalArgumentException - if address is blank; address.length() != 17; address does not split into 6 tokens (bytes)
NumberFormatException - if one of the byte tokens is not a byte in hexadecimal format
Method Detail

getBytes

public byte[] getBytes()
Returns a clone of the internal byte[] (to maintain encapsulation).


toString

public String toString()
Overrides:
toString in class Object

byteToString

public static String byteToString(byte b)