Practical No 14
Practical No 14
import java.io.*;
import java.net.*;
public class InetDemo
{
public static void main(String[] args)
{
try
{
InetAddress ip=InetAddress.getByName("localhost");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output :
Write a program using factory method
import java.net.*;
class FactoryMethodsDemo
{
public static void main(String ar[]) throws UnknownHostException
{
InetAddress addr1 = InetAddress.getLocalHost();
System.out.println(addr1);
InetAddress addr2 = InetAddress.getByName("msbte.org.in");
System.out.println(addr2);
InetAddress addr3[ ] = InetAddress.getAllByName("www.google.com");
for (int i=0; i<addr3.length; i++)
System.out.println(addr3[i]);
}
}
Output :