Resolving ip-address of a hostname

后端 未结 4 535
青春惊慌失措
青春惊慌失措 2020-12-02 14:59

I have the DNS server IP address and a hostname.

Using Java, how can I find the IP address of the hostname as returned by that DNS server using the IP address and th

4条回答
  •  悲&欢浪女
    2020-12-02 15:48

    As suggested by all above, you can use InetAddress.getByName("hostName") but this can give you a cached IP, Read the java documentation for the same. If you want to get a IP from DNS you can use:

    InetAddress[] ipAddress = DNSNameService.lookupAllHostAddr("hostName");
    

提交回复
热议问题