Как я могу найти количество бит, зарезервированных для сетевой части адреса?
Вот мой код в java:
public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> ifaces;
ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
System.out.println(iface);
// loop through all of the (potential) IP addresses configured to use "iface"
Enumeration<InetAddress> addresses = iface.getInetAddresses();
// Showing teh value, either ipv4 or ipv6
// and the number of bits reserved for the network portion of the address
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
String hostAddress = address.getHostAddress();
System.out.println("addr: " + address.);
if (address instanceof Inet4Address && !address.isLoopbackAddress()) {
System.out.println("IPv4: /" + hostAddress);
}
else if(address instanceof Inet6Address && !address.isLoopbackAddress()){
System.out.println("IPv6: /" + hostAddress);
}
}
}
}
Пример вывода, который я должен получить:
name:lo0 (lo0)
IPv6: /fe80:0:0:0:0:0:0:1%lo0, 64 bits reserved for the network
IPv6: /0:0:0:0:0:0:0:1%lo0, 128 bits reserved for the network
IPv4: /127.94.0.1, 8 bits reserved for the network
IPv4: /127.0.0.1, 8 bits reserved for the network
Как получить количество бит, зарезервированных для каждого mac-адреса?