/**
* Get device Hardwareaddress Address
* @return
*/
public static String getmachinehardwareaddress () {
enumeration<networkinterface> interfaces = null;
try {
interfaces = Networkinterface.getnetworkinterfaces ();
} catch (SocketException e) {
E.printstacktrace ();
}
String hardwareaddress = null;
NetworkInterface IF = null;
while (Interfaces.hasmoreelements ()) {
IF = Interfaces.nextelement ();
try {
hardwareaddress = bytestostring (If.gethardwareaddress ());
if (hardwareaddress = = null) continue;
} catch (SocketException e) {
E.printstacktrace ();
}
}
if (if! = null && if.getname (). Equals ("Wlan0")) {
hardwareaddress = Hardwareaddress.replace (":", "");
}
return hardwareaddress;
}
/***
* Byte converted to string
* @param bytes
* @return
*/
private static String bytestostring (byte[] bytes) {
if (bytes = = NULL | | bytes.length = = 0) {
return null;
}
StringBuilder buf = new StringBuilder ();
for (byte b:bytes) {
Buf.append (String.Format ("%02x:", b));
}
if (buf.length () > 0) {
Buf.deletecharat (Buf.length ()-1);
}
return buf.tostring ();
}
/**
* Get device IP Address
* @return
*/
public static String getmachineipaddress () {
enumeration<networkinterface> interfaces = null;
try {
interfaces = Networkinterface.getnetworkinterfaces ();
} catch (SocketException e) {
E.printstacktrace ();
}
String ipAddress = null;
NetworkInterface IF = null;
while (Interfaces.hasmoreelements ()) {
IF = Interfaces.nextelement ();
enumeration<inetaddress> addressenumeration = if.getinetaddresses ();
InetAddress address = addressenumeration.nextelement ();
ipAddress = bytestostring (Address.getaddress ());
if (ipAddress = = null) continue;
}
return ipAddress;
}
Get the MAC address and IP address of the device (android6.0 above)