Android 获取本机Mac 地址
2011-03-18 15:40
393 查看
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> 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;
}
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> 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;
}
相关文章推荐
- Android下如何获取Mac地址
- Android获取本机Mac地址及IP地址方法
- Android 获取Mac地址
- android获取mac地址出现的问题
- android 获取设备信息的IP地址和Mac地址—亲测无误!!
- Android获取本机Mac地址及IP地址方法
- Android: 用jni 获取MAC地址
- 获取 android 设备 mac 地址的方法
- Android获取Ethernet、WIFI的ip和mac地址
- android获取本机的IP地址和mac物理地址
- Android获取WIFI状态下的IP地址以及MAC地址
- Android: 用jni 获取MAC地址
- android设备无线、有线网络下获取MAC地址
- Android: 用jni 获取MAC地址
- android获取mac地址
- Android环境下稳妥获取mac地址的方法
- android:获取本机Mac地址及IP地址方法
- Android 获取以太网Mac地址和IP地址
- Android下获取以太网mac地址方法 非wifi
- android获取本机的IP地址和mac物理地址