zoukankan      html  css  js  c++  java
  • Java 获取本地IP地址

        private static String getIpAddress( ){
    
            String ip = "";
            Collection<InetAddress> colInetAddress =getAllHostAddress();
    
            for (InetAddress address : colInetAddress) {
                if (!address.isLoopbackAddress() && address.getHostAddress().contains(":") != true)
                    ip = ip + address.getHostAddress() + ",";
            }
    
            return ip;
        }
    
        public static Collection<InetAddress> getAllHostAddress() {
            try {
                Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
                Collection<InetAddress> addresses = new ArrayList<InetAddress>();
    
                while (networkInterfaces.hasMoreElements()) {
                    NetworkInterface networkInterface = networkInterfaces.nextElement();
                    Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
                    while (inetAddresses.hasMoreElements()) {
                        InetAddress inetAddress = inetAddresses.nextElement();
                        addresses.add(inetAddress);
                    }
                }
    
                return addresses;
            } catch (SocketException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
  • 相关阅读:
    点到圆的切点
    两圆交点
    问n条平行于x,y的直线交点个数
    凸包与直线的关系
    Kuangbin的计算几何模板
    最大空凸包
    树链剖分模板题
    笔记1
    面试题2
    python utf-8 转码问题
  • 原文地址:https://www.cnblogs.com/fupeng/p/6866061.html
Copyright © 2011-2022 走看看