Call Linux BusyBox and get Androidip with Linux commands

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.