// Read the Ethernet MAC in the directory CAT/sys/class/NET/eht0/address
// Read the MAC address of wifi or current network connection: CAT/sys/class/NET/wlan0/address
Public static string getmac (){
String macserial = NULL;
Try {
Process pp = runtime.getruntime(cmd.exe C (
"Cat/sys/class/NET/eht0/address ");
Inputstreamreader IR = new inputstreamreader (pp. getinputstream ());
Linenumberreader input = new linenumberreader (IR );
String STR = input. Readline ();
If (STR! = NULL ){
Macserial = Str. Trim (); // remove space
}
} Catch (ioexception ex ){
// Assign the default value
Macserial = "00: 00: 00: 00 ";
Ex. printstacktrace ();
}
Return macserial. Replace (":","");
}
// You can also use Linux commands to obtain
/*
* Public static string getmacaddress () {string result = ""; string MAC =
* ""; Result = callcmd ("busybox ifconfig", "hwaddr ");
*
* // If the returned result = NULL, the network cannot be obtained if (result = NULL) {return
* "Network error. Check the network ";}
*
* // Parse the row of Data // For example: eth0 link encap: Ethernet hwaddr 00: 16: E8: 3E: DF: 67 If
* (Result. Length ()> 0 & result. Contains ("hwaddr") = true) {MAC =
* Result. substring (result. indexof ("hwaddr") + 6, result. Length ()-1 );
* Log. I ("test", "Mac:" + Mac + "Mac. Length:" + Mac. Length ());
*
* If (Mac. Length ()> 1) {MAC = Mac. replaceall ("", ""); Result = "";
* String [] TMP = Mac. Split (":"); For (INT I = 0; I <TMP. length; ++ I ){
* Result + = TMP [I];} log. I ("test", result + "result. Length:" +
* Result. Length ();} return result ;}
*
* Public static string callcmd (string cmd, string filter) {string result =
* ""; String line = ""; try {process proc =
* Runtime.getruntime(cmd.exe C (CMD); inputstreamreader is = new
* Inputstreamreader (Proc. getinputstream (); bufferedreader BR = new
* Bufferedreader (is );
*
* // Execute the command cmd. Only the while (line = Br. Readline () containing the filter in the result is obtained ())! = NULL &&
* Line. Contains (filter) = false) {// result + = line; log. I ("test ",
* "Line:" + line );}
*
* Result = line; log. I ("test", "Result:" + result);} catch (exception E)
* {E. printstacktrace ();} return result ;}
*/