Get local Mac based on BusyBox
public static String Getlocalmacaddressfrombusybox () {
String result = "";
String Mac = "";
result = Callcmd ("BusyBox ifconfig", "HWaddr");
If the result = = NULL is returned, the network is not fetching
if (result==null) {
Return "Network error, please check the network";
}
Parsing this row of data
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];
}
}*/
result = Mac;
LOG.I ("Test", result+ "Result.length:" +result.length ());
}
return result;
}
private static string Callcmd (string cmd,string filter) {
String result = "";
String line = "";
try {
Process proc = Runtime.getruntime (). exec (CMD);
InputStreamReader is = new InputStreamReader (Proc.getinputstream ());
BufferedReader br = new BufferedReader (IS);
Executes command cmd, taking only the line containing the filter in the result
while (line = Br.readline ()) = 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;
}
Call Linux BusyBox and get Androidip with Linux commands