------ Solution ----------------------------- ---------------
android linux command execution does not require root privileges visually try
------ Solution ------ --------------------------------------
EthernetDevInfo mEthInfo = mEthManager. getSavedEthConfig ();
Log.i (TAG, "mEthInfo == null:" + (mEthInfo == null));
if (mEthInfo! = null) {
String ipAddress = mEthInfo.getIpAddress ();
String netMask = mEthInfo.getNetMask ();
String dns = mEthInfo.getDnsAddr ();
String gateWay = mEthInfo.getRouteAddr ();
------ Solution ----------------------- ---------------------
not to bicker , looks like you this way public static String getMacAddress () { and not all phones apply. I get their phone test it, and did not find eth0 this node.
My address is / sys/class/net/wlan0/address
------ For reference only -------------------- -------------------
amount , linux command , it should be able to see, but to show how the application of the android interface ah ? Seek advice
------ For reference only ------------------------------------ ---
EthernetDevInfo this class import android.net.ethernet.EthernetDevInfo; 'll be prompted to find ah , I did not find the api inside it, really like the others say EthernetDevInfo in the framework layer ? So, how do I use it ? Dumbfounded ,
------ For reference only -------------------------------- -------
the way the information has been attached , are collated from others , verified wood in question .
attached below for mac address , Ethernet IP access method, and under the wifi network access and information.
Get Mac Address:
public static String getMacAddress () {
try {
return loadFileAsString ("/ sys/class/net/eth0 / address ")
. toUpperCase (). substring ( 0 , 17 ) ;
} catch (Exception e) {
e.printStackTrace ();
return null;
}
}
obtained under the Ethernet IP:
public static String getLocalIpAddress () {
try {
for (Enumeration
. getNetworkInterfaces (); en.hasMoreElements () ;) {
NetworkInterface intf = en.nextElement ();
for (Enumeration
. getInetAddresses (); enumIpAddr.hasMoreElements () ;) {
InetAddress inetAddress = enumIpAddr.nextElement ();
if (! inetAddress.isLoopbackAddress ()) {
return inetAddress.getHostAddress (). toString ();
}
}
}
} catch (SocketException ex) {
Log.e ("WifiPreference IpAddress", ex.toString ());
}
return null;
}
wifi network information obtained under relevant :
wm = (WifiManager) getSystemService (Context.WIFI_SERVICE);
d = wm.getDhcpInfo ();
/ / The address code into a string type
public String FormatString (int value) {
String strValue = "";
byte [] ary = intToByteArray (value);
for (int i = ary.length-1; i> = 0; i -) {
strValue + = (ary & ; 0xFF);
if (i> 0) {
strValue + = ".";
}
}
return strValue;
}
public byte [] intToByteArray (int value) {
byte [] b = new byte [4];
for (int i = 0; i <4; i + +) {
int offset = (b.length - ; 1 - i) * 8;
b = (byte) (( value >>> offset) & 0xFF);
}
return b;
}
IP: FormatString (d.ipAddress). toString ();
Default Gateway : FormatString (d.gateway). toString ();
Subnet Mask : FormatString (d.netmask). toString ();
------ For reference only ------------------ ---------------------
mark about learning .
------ For reference only -------------------------------------- -
amount , the amount of my test was produced plate, not on the phone measured , sorry, forgot to illustrate !
没有评论:
发表评论