Android examples for java.net:Mac Address
get Mac From Arp Cache
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { public static String getMacFromArpCache(String ip) { if (ip == null) return null; BufferedReader br = null;/*from w w w .ja v a 2 s.co m*/ try { br = new BufferedReader(new FileReader("/proc/net/arp")); String line; while ((line = br.readLine()) != null) { String[] splitted = line.split(" +"); if (splitted != null && splitted.length >= 4 && ip.equals(splitted[0])) { // Basic sanity check String mac = splitted[3]; if (mac.matches("..:..:..:..:..:..")) { return mac; } else { return null; } } } } catch (Exception e) { e.printStackTrace(); } finally { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } return null; } }