Dave's Brain

Browse - Programming Tips - Is there an easy way to do a DNS lookup?

Date: 2016mar22
Language: Java

Q.  Is there an easy way to do a DNS lookup?

A.    Use the InetSocketAddress constructor:

try { InetSocketAddress addr = new InetSocketAddress("google.com", 80); System.out.println("address is " + addr.getAddress().toString()); } catch(IOException ex) { System.out.println("Can not lookup host"); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.