Java Mac Address Get getMACAddress()

Here you can find the source of getMACAddress()

Description

get MAC Address

License

Apache License

Declaration

public static String getMACAddress() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;

public class Main {
    private static InetAddress ip;

    public static String getMACAddress() {
        StringBuilder sb = new StringBuilder();

        try {//from w ww .  ja  v  a 2 s . c  om
            NetworkInterface network = NetworkInterface
                    .getByInetAddress(ip);
            byte[] mac = network.getHardwareAddress();

            for (int i = 0; i < mac.length; i++) {
                sb.append(String.format("%02X%s", mac[i],
                        (i < mac.length - 1) ? "-" : ""));
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
}

Related

  1. getMac()
  2. getMacAddr()
  3. getMacAddress()
  4. getMacAddress()
  5. getMACAddress()
  6. getMacAddress()
  7. getMacAddress()