Here you can find the source of getMacAddress()
public static String getMacAddress()
//package com.java2s; //License from project: Apache License import java.net.NetworkInterface; import java.util.Collections; public class Main { /**/*from w ww . ja va 2 s . c o m*/ * Returns the MAC address of the first network interface that is found. * * @return MAC address of <tt>null</tt> if no network address was found. */ public static String getMacAddress() { try { String mac = null; for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (ni.getHardwareAddress() != null) { byte[] hwAddr = ni.getHardwareAddress(); if (hwAddr.length > 0) { mac = ""; for (int i = 0; i < hwAddr.length; i++) { mac += String.format("%02X%s", hwAddr[i], (i < hwAddr.length - 1) ? ":" : ""); } break; } } } return mac; } catch (Exception e) { e.printStackTrace(); return null; } } }