android 获取网卡mac_Android获取本机Mac地址及IP地址方法
1、Android? 獲取本機(jī)Mac 地址方法:
需要在AndroidManifest.xml文件中添加權(quán)限:
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
2、Android 獲取本機(jī)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
評(píng)論
不在wifi環(huán)境下怎么獲取mac地址?
3 樓
woyaowenzi
2013-12-10
這只能針對(duì)android4.0一下版本? 用這個(gè)方法在4.0抓取的為IPv6地址格式
1 樓
luobo25
2011-10-20
2、Android 獲取本機(jī)IP地址方法
現(xiàn)在需要權(quán)限android.permission.INTERNET
總結(jié)
以上是生活随笔為你收集整理的android 获取网卡mac_Android获取本机Mac地址及IP地址方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: for vue 一行2列_vue常见面试
- 下一篇: pythontuple数据类型_Pyth