External Interfaces/API | ![]() ![]() |
Example - Finding an Internet Protocol Address
The resolveip
function returns either the name or address of an IP (internet protocol) host. If you pass resolveip
a hostname, it returns the IP address. If you pass resolveip
an IP address, it returns the hostname. The function uses the Java API class java.net.InetAddress
, which enables you to find an IP address for a hostname, or the hostname for a given IP address, without making DNS calls.
resolveip
calls a static
method on the InetAddress
class to obtain an InetAddress
object. Then, it calls accessor methods on the InetAddress
object to get the hostname and IP address for the input argument. It displays either the hostname or the IP address, depending on the program input argument.
![]() | Running the Example | Description of resolveip | ![]() |