记录几种识别机器唯一码的方式

来源:互联网 发布:linux 启动mysql 编辑:程序博客网 时间:2024/06/03 20:56

1.cpu串号

2.imei串号

3.mac地址

详细如下

 // 1.获取CPU串号 
public static String getCPUSerial() { 
String str = "", strCPU = "", cpuAddress = "0000000000000000"; 
try { 
// 读取CPU信息 
Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo"); 
InputStreamReader ir = new InputStreamReader(pp.getInputStream()); 
LineNumberReader input = new LineNumberReader(ir); 
// 查找CPU序列号 
for (int i = 1; i < 100; i++) { 
str = input.readLine(); 
if (str != null) { 
// 查找到序列号所在行 
if (str.indexOf("Serial") > -1) { 
// 提取序列号 
strCPU = str.substring(str.indexOf(":") + 1, str.length()); 
cpuAddress = strCPU.trim(); 
break; 



} catch (Exception ex) { 
// 赋予默认值 
ex.printStackTrace(); 

return cpuAddress; 
}

//2.获取imei

public static String getImeiSerial(Context context){ 
try { 
if(null==imeiSerial && null!=context){ 
boolean mobileMark = false; 
ConfigManager configManager = (ConfigManager) context.getSystemService(Context.CONFIG_SERVICE); 
if(null!=configManager) mobileMark = configManager.getMobileSupportState(); 
if(mobileMark){ 
TelephonyManager mTelephonyManager = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)); 
if(null!=mTelephonyManager) imeiSerial = mTelephonyManager.getDeviceId(); 


} catch (Exception e) { 
e.printStackTrace(); 

return imeiSerial; 
}


//3.获取mac地址

public static String getLocalMacAddressFromWifiInfo(Context context){
         WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);  
         WifiInfo info = wifi.getConnectionInfo();  
         return info.getMacAddress(); 
     }

原创粉丝点击