Using method getByName to retrieve IP address of a specifi ed host
It is sometimes useful for Java programs to be able to retrieve the IP address of
the current machine. The example below shows how to do this.
public class MyLocalIPAddress
public static void main(String args)
InetAddress address =
catch (UnknownHostException uhEx)
"Could not fi nd local address!");
Output from this program when run on the author's offi ce machine is shown in
Fig. 2.2 .