Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Practical 14ajp

Uploaded by

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

Practical 14ajp

Uploaded by

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

Practical 14

1.
import java.net.InetAddress; import
java.net.UnknownHostException;
public class InetAddressExample {
public static void main(String[] args)

try {

InetAddress localHost = InetAddress.getLocalHost();

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

System.out.println("Local Host IP Address: " + localHost.getHostAddress());

String hostname = "google.com";

InetAddress remoteHost = InetAddress.getByName(hostname);

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

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

} catch (UnknownHostException e) {

System.err.println("Host not found: " + e.getMessage());

} catch (Exception e) {

System.err.println("An error occurred: " + e.getMessage());

}
Output :-
2.
import java.io.*;

import java.net.*;
public class InetDemo {

public static void main(String[] args) {


try {
InetAddress ip = InetAddress.getByName("www.google.com");
System.out.println("Host Name: " + ip.getHostName());
System.out.println("IP Address: " + ip.getHostAddress());
} catch (Exception e) {
System.out.println(e);
}
}
}

Output :-

You might also like