android 獲取本機的IP地址和mac物理地址的實現(xiàn)方法
更新時間:2016年09月07日 14:18:43 投稿:lqh
本文主要介紹android 獲取本機的IP地址和mac物理地址的實現(xiàn)方法,這里提供示例代碼,實現(xiàn)功能,有需要的小伙伴可以參考下
獲取本機IP地址
public String getLocalIpAddress() { WifiManager wifiManager = (WifiManager) getSystemService(android.content.Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); try { return InetAddress.getByName(String.format("%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff))).toString(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
獲取本機的物理地址
public String getLocalMacAddress() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); }
以上就是Android 獲取手機 IP和MAC地址的方法,希望能幫助到讀者,謝謝大家對本站的支持!
您可能感興趣的文章:
- Android開發(fā)獲取手機內(nèi)網(wǎng)IP地址與外網(wǎng)IP地址的詳細方法與源碼實例
- Android獲得設(shè)備狀態(tài)信息、Mac地址、IP地址的方法
- Android中使用adb命令通過IP地址連接手機
- Android實現(xiàn)IP地址輸入框的方法示例代碼
- Android開發(fā)實現(xiàn)在Wifi下獲取本地IP地址的方法
- Android 判斷ip地址合法實現(xiàn)代碼
- Android 獲取IP地址的實現(xiàn)方法
- android實現(xiàn)獲取有線和無線Ip地址的方法
- Android手機獲取IP地址的兩種方法
- Android開發(fā)準確獲取手機IP地址的兩種方式
相關(guān)文章
Android使用Messenger實現(xiàn)service與activity交互
這篇文章主要介紹了android使用Messenger實現(xiàn)service與activity交互的相關(guān)資料,需要的朋友可以參考下2016-06-06Android HTTP網(wǎng)絡(luò)請求的異步實現(xiàn)
這篇文章主要介紹了Android HTTP網(wǎng)絡(luò)請求的異步實現(xiàn),感興趣的小伙伴們可以參考一下2016-07-07Android ViewPager實現(xiàn)輪播圖效果
這篇文章主要為大家詳細介紹了Android ViewPager實現(xiàn)輪播圖效果的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02