Choose DNS server for resolving hostnames in Java

前端 未结 1 1924
北荒
北荒 2020-12-30 05:17

resolving a hostname to an IP address is rather easy in Java by using the InetAddress class like this:

InetAddress address = InetAddress.getByName(\         


        
相关标签:
1条回答
  • 2020-12-30 05:36

    If you use Sun Java, you can use this code:

    //Override system DNS setting with Google free DNS server
    System.setProperty("sun.net.spi.nameservice.nameservers", "8.8.8.8");
    System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
    

    See this blog post: How to set a custom DNS server with Java System properties for more details.

    0 讨论(0)
提交回复
热议问题