您的位置:首页 > 编程语言

获取手机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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: