Oct 17

You can use the getNetworkPrefixLength() method in the InterfaceAddress class to get the size of the mask.

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

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

written by objects \\ tags: , , ,


One Response to “Get subnet mask using java”

  1. Latoya Says:

    Outstanding post, I conceive website owners should acquire a lot from this weblog its really user friendly 🙂

Leave a Reply

You must be logged in to post a comment.