android 获取本机的IP地址和mac物理地址的实现方法
获取本机IP地址
publicStringgetLocalIpAddress(){ WifiManagerwifiManager=(WifiManager)getSystemService(android.content.Context.WIFI_SERVICE); WifiInfowifiInfo=wifiManager.getConnectionInfo(); intipAddress=wifiInfo.getIpAddress(); try{ returnInetAddress.getByName(String.format("%d.%d.%d.%d", (ipAddress&0xff),(ipAddress>>8&0xff), (ipAddress>>16&0xff),(ipAddress>>24&0xff))).toString(); }catch(UnknownHostExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } returnnull; }
获取本机的物理地址
publicStringgetLocalMacAddress(){ WifiManagerwifi=(WifiManager)getSystemService(Context.WIFI_SERVICE); WifiInfoinfo=wifi.getConnectionInfo(); returninfo.getMacAddress(); }
以上就是Android获取手机 IP和MAC地址的方法,希望能帮助到读者,谢谢大家对本站的支持!