本文介绍了如何使用java获取本地系统的子网掩码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Java编程获取 Subnet 本地系统的掩码地址?

How to get Subnet mask address of local system using Java programming?

推荐答案

localhost接口的第一个地址的网络掩码:

the netmask of the first address of the localhost interface:

InetAddress localHost = Inet4Address.getLocalHost();
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
networkInterface.getInterfaceAddresses().get(0).getNetworkPrefixLength();

更完整的方法:

InetAddress localHost = Inet4Address.getLocalHost();
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);

for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
    System.out.println(address.getNetworkPrefixLength());
}

/ 24表示255.255.255。

/24 means 255.255.255.

这篇关于如何使用java获取本地系统的子网掩码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 05:32