码迷,mamicode.com
首页 > 移动开发 > 详细

获取手机本地IP地址

时间:2017-11-10 16:50:29      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:except   cat   ati   back   inter   elements   ret   exception   soc   

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) {
        }
        return null;
    }

 

获取手机本地IP地址

标签:except   cat   ati   back   inter   elements   ret   exception   soc   

原文地址:http://www.cnblogs.com/loaderman/p/7815149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!