As stated under the Ethernet I can get to the IP address, does anyone know subnet mask, default gateway, DNS if get ah? Note that the Ethernet connection under Oh, no wifi!
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Try to perform visual android linux command does not require root privileges
Reply:
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 ();
Reply:
Amount, linux commands, it should be able to see, but to show how the android application interface ah? Seek advice
Reply:
EthernetDevInfo this class import android.net.ethernet.EthernetDevInfo;'ll be prompted to find ah, I did not find the api inside it, it really like people say EthernetDevInfo in the framework layer? So, how do I use it? Dumbfounded,,,,
Reply:
The method of information has been attached, are collated from others, verified wood in question.
Attached below to get mac address, get IP Ethernet and method to get under way next wifi network 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;
}
}
Get IP Ethernet under:
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 under the access to relevant information:
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 ();
Reply:
Not to bicker, looks like you this method public static String getMacAddress () {does not apply in all phones. I take their phones to test it, and did not find eth0 this node.
My address is / sys/class/net/wlan0/address
Reply:
mark about learning.
Reply:
Amount, the amount of my test is produced on flat, not measured on the phone, sorry, forgot to explain it!
No comments:
Post a Comment