当接口关闭时,如何在Java中读取网络接口静态IP

当接口关闭时,如何在Java中读取网络接口静态IP,java,ip-address,ipv4,network-interface,static-ip-address,Java,Ip Address,Ipv4,Network Interface,Static Ip Address,在我的windows系统上有两个NIC,每个NIC配置为不同的静态IP(例如:IP_1=170.10.120.1和IP_2=10.20.30.1),使用以下Java代码,我能够将两个接口IP打印到控制台 Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { System.

在我的windows系统上有两个NIC,每个NIC配置为不同的静态IP(例如:IP_1=170.10.120.1和IP_2=10.20.30.1),使用以下Java代码,我能够将两个接口IP打印到控制台

Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
System.out.println("netint.isUp()" + netint.isUp());
System.out.println("netint.getInterfaceAddresses()" + netint.getInterfaceAddresses());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
System.out.println("Collections.list(inetAddresses)" + Collections.list(inetAddresses));
Enumeration nets=NetworkInterface.getNetworkInterfaces();
用于(网络接口netint:Collections.list(nets)){
System.out.println(“netint.isUp()”+netint.isUp());
System.out.println(“netint.getInterfaceAddresses()”+netint.getInterfaceAddresses());
枚举inetAddresses=netint.getInetAddresses();
System.out.println(“Collections.list(inetAddresses)”+Collections.list(inetAddresses));
当网络_2暂时关闭时,执行上述Java代码只将IP_1打印到控制台,但IP_2返回为空。由于两者都有静态IP,即使接口_2关闭,我也需要检索两个接口详细信息并将其静态IPV4 IP打印到控制台


如何实现这一点?我如何检索两个接口的静态IP,并使用Java将它们打印到控制台,即使其中一个接口已关闭?

当然,如果接口已关闭,则根据定义它没有地址?网络接口已配置静态IP地址。因此,当网络关闭或LAN电缆刚刚重新连接时移动后,在适配器设置下,仍然可以在接口属性中看到接口IPV4 IP。有没有任何方法可以获得该接口的静态IP,该IP是从Java下载的?