The following code:
InetAddress localHost = Inet4Address.getLocalHost();
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
System.out.println(address.getAddress() + "/" + address.getNetworkPrefixLength());
}
returns:
/fe80:0:0:0:11da:433a:412a:8c23%13/64
/192.168.1.107/128
My subnet mask is /24, not /128. Is it a Java bug?
Maybe you hit this bug: http://bugs.sun.com/view_bug.do?bug_id=6707289
(Please stop to upvote ... this was only 1 google away ...)
adding to the information base, with the ipconfig output below, i get some strange prexix lengths on jdk 1.8/windows 8.1:
At least it doesn't make any sense to me...
/128
can't be valid for IP4 networks (/32
should be the highest (and most useless ;) ) value and describe a network with a single address, like a network mask255.255.255.255
)./128
would be the same for IP6, a network with just one address (= a 128 bit fixed prefix).