📜  java inetaddress 解决方法如何使本地主机安全 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:08.441000             🧑  作者: Mango

代码示例1
public static List getIPAddress() throws SocketException {

    List ipAddresses = new ArrayList();
    Enumeration e;
    e = NetworkInterface.getNetworkInterfaces();
    while (e.hasMoreElements()) {
        NetworkInterface ni = (NetworkInterface) e.nextElement();
        if (ni.isLoopback() || !ni.isUp()) continue;

        for (Enumeration e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) {
            InetAddress ip = (InetAddress) e2.nextElement();
            ipAddresses.add(ip);
        }
    }
    return ipAddresses;
}