get LAN Mac Address from /sys/class/net/eth0/address - Android Network

Android examples for Network:Mac Address

Description

get LAN Mac Address from /sys/class/net/eth0/address

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String getLANMacAddress() {
        String filePath = "/sys/class/net/eth0/address";
        StringBuffer fileData = new StringBuffer(1000);
        BufferedReader reader;/*from ww w  . j a va2 s. co  m*/
        try {
            reader = new BufferedReader(new FileReader(filePath));
            char[] buf = new char[1024];
            int numRead = 0;
            while ((numRead = reader.read(buf)) != -1) {
                String readData = String.valueOf(buf, 0, numRead);
                fileData.append(readData);
            }
            reader.close();
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return fileData.toString();
    }
}

Related Tutorials