InterfaceAddress getNetworkPrefixLength Example
InterfaceAddress class getNetworkPrefixLength example. This example shows you how to use getNetworkPrefixLength method.
InterfaceAddress class getNetworkPrefixLength example. public short getNetworkPrefixLength() Returns the network prefix length for this address. This is also known as the subnet mask in the context of IPv4 addresses. Typical IPv4 values would be 8 (255.0.0.0), 16 (255.255.0.0) or 24 (255.255.255.0).Typical IPv6 values would be 128 (::1/128) or 10 (fe80::203:baff:fe27:1243/10)
Here is the code
/*
* @ # GetNetworkPrefixLength.java
* A class repersenting use to GetNetworkPrefixLength method
* of InterfaceAddress class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
import java.util.*;
public class GetNetworkPrefixLength {
public static void main(String args[]) throws Exception {
NetworkInterface networkInterface =
NetworkInterface.getByName("eth0");
List<InterfaceAddress> address =
networkInterface.getInterfaceAddresses();
for (InterfaceAddress interfaceAddress : address) {
System.out.println("Network Prefix Length " +
interfaceAddress.getNetworkPrefixLength());
}
}
} |
Output
Network Prefix Length 64
Network Prefix Length 24 |
|