0

4.2 Design an application that will list all the IP addresses of a particular site (e.g. google.com) and then compare each address displayed with every other address and determine which ones are equal. It will also output the hashcodes, address types and state whether the address is of Class A, B, C or D. Assume that classful addressing has been used. 4.3 Modify the program in 5.2 so that the exact subnet mask and network number is output for all IP addresses where the addressing scheme could be both classful or classless. Hint: You may use SubnetUtils or getNetworkPrefixlength

im having trouble with part 4.3. i tried some code that i found online, but it is working only for localHost addresses. when im trying with the ip of google.com, it throws nullpointerException

   InetAddress I = Inet4Address.getByName("8.8.8.8");
   NetworkInterface networkInterface = NetworkInterface.getByInetAddress(I);
   System.out.println(networkInterface.getInterfaceAddresses().get(1).getNetworkPrefixLength());`

an error occurs at the last line

thanks in advance for the help

Ritesh A
  • 1
  • 1

0 Answers0