把已经得到的信息的方法附上,都是从别人那里整理的,验证过木有问题。
下面附上获取mac地址,以太网下获取IP的方法以及wifi下获取网络信息的方法。
获取Mac地址:
public static String getMacAddress(){
try {
return loadFileAsString(“/sys/class/net/eth0/address”)
.toUpperCase().substring(0, 17);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
以太网下获取IP:
public static String getLocalIpAddress() {
try {
for (Enumeration en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return ine