Here you can find the source of getMacAddress(String host)
@SuppressWarnings("unused") public String getMacAddress(String host)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.*; public class Main { public static String getMacAddress() { String mac = ""; String line = ""; String os = System.getProperty("os.name"); if (os != null && os.startsWith("Windows")) { try { String command = "cmd.exe /c ipconfig /all"; Process p = Runtime.getRuntime().exec(command); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = br.readLine()) != null) { if (line.indexOf("Physical Address") > 0) { int index = line.indexOf(":") + 2; mac = line.substring(index); break; }// w w w .j av a 2s. c o m } br.close(); } catch (IOException e) { e.printStackTrace(); } } return mac; } @SuppressWarnings("unused") public String getMacAddress(String host) { String mac = ""; StringBuffer sb = new StringBuffer(); try { NetworkInterface ni = NetworkInterface.getByInetAddress(InetAddress.getByName(host)); } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } mac = sb.toString(); mac = mac.substring(0, mac.length() - 1); return mac; } }