InetAddress GetAllByName() Example
returns an array of its IP addresses, based on the configured name service on the system.
InetAddressclass GetAllByName() method example. This example shows you how to use GetAllByName() method.This method returns an array of its IP addresses, based on the configured name service on the system.
Here is the code:-
/*
* @Program that returns an array of its IP addresses, based on the configured
name service on the system.
* GetAllByName.java
* Author:-RoseIndia Team
* Date:-19-Jun-2008
*/
import java.net.*;
public class GetAllByName {
public static void main(String[] args) throws UnknownHostException {
//returns an array of its IP addresses,
InetAddress ia[] = InetAddress.getAllByName("girish-desktop");
System.out.print("IP address is: ");
for (int i = 0; i < ia.length; i++) {
System.out.println(ia[i]);
}
}
} |
Output of the program:-
| IP address is: girish-desktop/127.0.1.1 |
|