O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding IP Addresses and Domain Names

// find IP address for given domain
											String hostName = www.timothyfisher.com";
											String ip =
											InetAddress.getByName(hostName).getHostAddress();
											// find domain name for ip address
											String ipAddress = "66.43.127.5";
											String hostName =
											InetAddres.getByName(ipAddress).getHostName();

In this phrase, we get a hostname when you know the IP address of a remote host, and we get an IP address when you start with the hostname of the remote host. To accomplish both of these tasks, we rely on the InetAddress class.

We use the getByName() static method of the InetAddress class to create an InetAddress instance. We can pass either an IP address or a hostname into the getByName() method to create the InetAddress instance. Once ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required