2

I have a simple java program that will print the dns name of IP address.

package p1;

import java.net.InetAddress;

public class Main {

    public static void main(String[] args) throws Exception {

        System.out.println(InetAddress.getByName("201.23.160.63").getHostName());
        System.out.println(InetAddress.getByName("191.207.99.75").getHostName());

    }
}

the above program displays

  • 201-23-160-63.gprs.claro.net.br
  • 191.207.99.75

However, on the command line (linux host command), the dns for the two IPs are found. Command line IPs dns

Why does InetAddress.getHostName() not get the dns for IP 191.207.99.75 (191-207-99-75.user.vivozap.com.br) as shown in the command line? or what would be a way to achieve this in java?

cgean
  • 21
  • 2
  • Possible duplicate of [Why does InetAddress.getLocalHost().getHostName() return a value different from bash "hostname"?](https://stackoverflow.com/questions/11143880/why-does-inetaddress-getlocalhost-gethostname-return-a-value-different-from) – Ben May 15 '18 at 14:11
  • These are different commands. One uses the Host command to get the dns from a remote IP, while the other uses the Hostname command to get the machine name. – cgean May 21 '18 at 19:39

0 Answers0