获取手机ip地址——工具代码
2014-06-23 13:16
309 查看
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(LOG_TAG,
ex.toString());
}
return
null;
}
{
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(LOG_TAG,
ex.toString());
}
return
null;
}
相关文章推荐
- 安卓 获取手机IP地址的实现代码
- 获取本手机IP地址
- 关于android4.0 获取手机IP地址的问题
- 获取手机ip地址
- 如何让jsp和js获取来源页地址和ip原理及代码
- 获取手机IP地址
- 获取手机Ip地址
- 用纯Java代码根据IP获取windows和linux的MAC物理地址
- ios 获取手机ip地址
- wap获取手机号码,今天uc开启云加速,用公司的工具类获取是null,但是另外一个项目可以,应该这个项目的工具旧少了一些代码。。,网上找了 方法自己加可以
- android设备获取当前所用网络类型和获取手机ip地址
- VC获取本机IP、子网掩码、网关、计算广播地址等信息代码(通过读注册表)
- Android获取手机IP地址
- 如何让jsp和js获取来源页地址和ip原理及代码
- nodejs获取本机内网和外网ip地址的实现代码
- android手机获取gps和基站的经纬度地址实现代码
- linux编程--c代码获取本机IP地址
- Linux下靠谱的获取本机IP地址的C代码实现
- C#获取路由器外网IP,MAC地址的实现代码
- iOS 获取手机IP地址