1.获取mac地址
public String getWlanMac() {
String str="";
String macSerial="";
try {
Process pp = Runtime.getRuntime().exec(
"cat /sys/class/net/wlan0/address ");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for (;null != str;) {
str = input.readLine();
if (str != null) {
macSerial = str.trim();
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
2.获取ip地址
public String getIp() {
String ip = mContext.getResources().getString(R.string.defalut_txt);
android.net.NetworkInfo.State mobile = mConnectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).getState();
android.net.NetworkInfo.State wifi = mConnectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).getState();
if (mobile == android.net.NetworkInfo.State.CONNECTED
|| mobile == android.net.NetworkInfo.State.CONNECTING) {
ip = getLocalIpAddress();
}
if (wifi == android.net.NetworkInfo.State.CONNECTED
|| wifi == android.net.NetworkInfo.State.CONNECTING) {
wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
ip = (ipAddress & 0xFF) + "." +
((ipAddress >> 8) & 0xFF) + "." +
((ipAddress >> 16) & 0xFF) + "." +
(ipAddress >> 24 & 0xFF);
}
return ip;
}
private String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
return inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "";
}
3.获取SN号
public String getAndroidOsSystemProperties() {
String ret;
Method systemProperties_get = null;
try {
systemProperties_get = Class.forName("android.os.SystemProperties").getMethod("get", String.class);
if ((ret = (String) systemProperties_get.invoke(null, "ro.serialno")) != null)
return ret;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}