0% found this document useful (0 votes)
9 views3 pages

Inet Address, Java 6

The document contains Java code examples demonstrating the use of the InetAddress class for network operations. It includes retrieving the local host address, resolving a hostname to an IP address, and comparing two InetAddress objects for equality. Each example is encapsulated in its own class with exception handling for potential errors.

Uploaded by

Saniya Bonde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Inet Address, Java 6

The document contains Java code examples demonstrating the use of the InetAddress class for network operations. It includes retrieving the local host address, resolving a hostname to an IP address, and comparing two InetAddress objects for equality. Each example is encapsulated in its own class with exception handling for potential errors.

Uploaded by

Saniya Bonde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

INET ADDRESS

import java.net.InetAddress;

class Inet {

public static void main(String args[]) throws Exception {

InetAddress add = InetAddress.getLocalHost();

System.out.println(add);

import java.net.*;

public class Inet1 {

public static void main(String[] args) {

try {

InetAddress ip = InetAddress.getByName("www.pvgcoet.ac.in");

System.out.println("Host Name: " + ip.getHostName());

System.out.println("IP Address: " + ip.getHostAddress());


} catch (Exception e) {

System.out.println(e);

import java.net.InetAddress;

public class InetAddressMethods {

public static void main(String s[]) {

try {

InetAddress ip1 = InetAddress.getByName("www.google.com");

InetAddress ip2 = InetAddress.getByName("www.google.com");

if (ip1.equals(ip2)) {

System.out.println("Both are equal");

} else {
System.out.println("Both are not equal");

} catch (Exception e) {

System.out.println(e);

You might also like