android 获取网卡mac_Android获取本机Mac地址及IP地址方法
1、Android? 獲取本機Mac 地址方法:
需要在AndroidManifest.xml文件中添加權限:
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
2、Android 獲取本機IP地址方法:
public 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 inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e("WifiPreference IpAddress", ex.toString());
}
return null;
}
分享到:
2010-05-14 17:23
瀏覽 57657
評論
不在wifi環境下怎么獲取mac地址?
3 樓
woyaowenzi
2013-12-10
這只能針對android4.0一下版本? 用這個方法在4.0抓取的為IPv6地址格式
1 樓
luobo25
2011-10-20
2、Android 獲取本機IP地址方法
現在需要權限android.permission.INTERNET
總結
以上是生活随笔為你收集整理的android 获取网卡mac_Android获取本机Mac地址及IP地址方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: for vue 一行2列_vue常见面试
- 下一篇: pythontuple数据类型_Pyth