Programming Tips - Java: Best way to resolve a DNS name into an IP-address

Date: 2015may15 Language: Java Keywords: lookup Q. Java: Best way to resolve a DNS name into an IP-address A. use InetAddress.getByName() like this:
import java.net.InetAddress; import java.net.UnknownHostException; String lookupHostIp(final String host) { String address = null; try { InetAddress a = java.net.InetAddress.getByName(host); address = a.getHostAddress(); } catch (UnknownHostException e) { address = "0.0.0.0"; } return address; }