I use this function to get device MAC address
public static String getMacAddress(){
try {
return loadFileAsString("/sys/class/net/eth0/address")
.toUpperCase().substring(0, 17);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Now I need to also get mac address of router this ethernet is connected to. How can I do that?
You should use
getBSSID()
of WifiInfo class will return the MAC address of remote access point.According to google docs it returns the basic service set identifier (BSSID) of the current access point in a form of mac address. The BSSID may be null if there is no network currently connected.
See here an example: