MAC address is the physical address, which uniquely identifies each device on a given network. To make communication between 2 networked devices, we need 2 addresses: IP address and MAC address. It stands for Media Access Control, and also known as Physical address, hardware address. It works on data link layer of OSI model. It is provided by device’s vendor at the time of manufacturing and embedded in its NIC, which is ideally cannot be changed
Types of MAC Address
1. Unicast MAC Address
2. Multicast MAC Address
3. Broadcast MAC Address
Steps to find MAC address
1. Click Window Start or press Windows key
2.In the given search box, type cmd to open command prompt
3. Press enter key, and command prompt window will display
4. Type ipconfig/ all commands and press enter
5. It will show different information, scroll down and look for physical address. Each Physical address is MAC address of your choice
Since JDK 1.6 Java developers are able to access address network card detail via http://NetworkInterface class. In this example we show you how to get localhost MAC address in java
package com.mykyong; import java.net.InetAddress; import java.net.NetworkInterface; import javanet.SocketException; import javanet.UnknownHostException; public class App{ public static void main(String[] args){ InetAddress ip; try { ip = InetAddress.getLocalHost()' System.out.println("Current MAC address :"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } System.out.println(sb.toString()); }
Output:
Current IP address : 192.168.1.22 Current MAC address : 00-26-B9-9B-61-BF
A MAC Address consists of six sets of two characters, each separated by colon.00:1B:44:11:3A:B7 is an example of a MAC. A MAC address is 48- bit hexadecimal address