How to get a domain name IP address with Java? The class that provides this feature is called java.net.inetaddress. We assume that there is such a domain name, which uses a static getByName to re-get an inetdress, then get the IP address that can be read. The following code is a very basic command line. import java.net.InetAddress; import java.net.UnknownHostException; public class NsLookup {static public void main (String [] args) {try {InetAddress address = InetAddress.getByName (args [0]); System.out.println ( Args [0] ":" address.getdress ());} catch (unknownhostException UHE {system.err.println ("Unable to find:" args [0]);}}} inetaddress can also be used GetDress () to get an IP address, but its return value is a 4-byte array. Therefore, although getadDress () is useful in obtaining IP, it is not suitable for output. The result of the above command is like this: Bash $ java code.nslookup www.sun.com www.sun.com: 192.18.97.241 Sometimes a domain name contains more than one IP address, such as Microsoft's web server, this is for Keep the load balance. Inetaddress provides a way to get all IP addresses of a domain name.