0% found this document useful (0 votes)
3 views

Prac 8 Output Java

The document provides a Java program that demonstrates how to retrieve the IP address and hostname using the InetAddress class. It includes methods to check various properties of the IP address, such as whether it is a local or multicast address. The conclusion emphasizes the understanding gained from the practical exercise on hostname retrieval.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Prac 8 Output Java

The document provides a Java program that demonstrates how to retrieve the IP address and hostname using the InetAddress class. It includes methods to check various properties of the IP address, such as whether it is a local or multicast address. The conclusion emphasizes the understanding gained from the practical exercise on hostname retrieval.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Input;

import java.net.Inet4Address;
import java.util.Arrays;
import java.net.InetAddress;
public class InetDemo2
{
public static void main(String[] arg) throws Exception
{
InetAddress ip = Inet4Address.getByName("www.javatpoint.com");
InetAddress ip1[] = InetAddress.getAllByName("www.javatpoint.com");
byte addr[]={72, 3, 2, 12};
System.out.println("ip : "+ip);
System.out.print("\nip1 : "+ip1);
InetAddress ip2 = InetAddress.getByAddress(addr);
System.out.print("\nip2 : "+ip2);
System.out.print("\nAddress : " +Arrays.toString(ip.getAddress()));
System.out.print("\nHost Address : " +ip.getHostAddress());
System.out.print("\nisAnyLocalAddress : " +ip.isAnyLocalAddress());
System.out.print("\nisLinkLocalAddress : " +ip.isLinkLocalAddress());
System.out.print("\nisLoopbackAddress : " +ip.isLoopbackAddress());
System.out.print("\nisMCGlobal : " +ip.isMCGlobal());
System.out.print("\nisMCLinkLocal : " +ip.isMCLinkLocal());
System.out.print("\nisMCNodeLocal : " +ip.isMCNodeLocal());
System.out.print("\nisMCOrgLocal : " +ip.isMCOrgLocal());
System.out.print("\nisMCSiteLocal : " +ip.isMCSiteLocal());
System.out.print("\nisMulticastAddress : " +ip.isMulticastAddress());
System.out.print("\nisSiteLocalAddress : " +ip.isSiteLocalAddress());
System.out.print("\nhashCode : " +ip.hashCode());
System.out.print("\n Is ip1 == ip2 : " +ip.equals(ip2));
}
}

Output :

Conclusion :
In this Practical we understand that how to retrieve
hostname using methods in InetAddress class.
K S P A T

You might also like