houzheng
public static ArrayList<String> getLocalIpAddr()
    {
        ArrayList<String> ipList = new ArrayList<String>();
        InetAddress[] addrList;
        try 
        {
            Enumeration interfaces=NetworkInterface.getNetworkInterfaces();
            while(interfaces.hasMoreElements())
            {
                NetworkInterface ni=(NetworkInterface)interfaces.nextElement();
                Enumeration ipAddrEnum = ni.getInetAddresses();
                while(ipAddrEnum.hasMoreElements())
                {
                    InetAddress addr = (InetAddress)ipAddrEnum.nextElement();
                    if (addr.isLoopbackAddress() == true)
                    {
                        continue;
                    }
                    
                    String ip = addr.getHostAddress();
                    if (ip.indexOf(":") != -1)
                    {
                        //skip the IPv6 addr
                        continue;
                    }
                    ipList.add(ip);
                }
            }            
            
            Collections.sort(ipList);
        }
        catch (Exception e) 
        {            
            e.printStackTrace();
        }
        
        return ipList;
    }

 

分类:

技术点:

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2021-12-24
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-11-02
  • 2021-06-01
  • 2022-12-23
  • 2021-09-25
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案