返回顶部

收藏

Android 获得手机ip地址

更多
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,Android,java

收藏

0人收藏

支持

0

反对

0