0% found this document useful (0 votes)
8 views5 pages

Problem Statement: Write A Program For DNS Lookup. Give An IP Address Input, It Should Return URL and Vice Versa

The document describes a Java program that performs DNS lookups, allowing users to input either a host name or an IP address to retrieve the corresponding information. The program utilizes the InetAddress class to resolve host names to IP addresses and vice versa, handling exceptions for unknown hosts. The output demonstrates successful conversions between host names and IP addresses.

Uploaded by

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

Problem Statement: Write A Program For DNS Lookup. Give An IP Address Input, It Should Return URL and Vice Versa

The document describes a Java program that performs DNS lookups, allowing users to input either a host name or an IP address to retrieve the corresponding information. The program utilizes the InetAddress class to resolve host names to IP addresses and vice versa, handling exceptions for unknown hosts. The output demonstrates successful conversions between host names and IP addresses.

Uploaded by

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

PROBLEM STATEMENT

Write a program for DNS lookup. Give an IP address


input , it should return URL and vice versa
Import java.util.*;

public class IPDemo


{
public static void main(String[] args){
String host;
Scanner ch = new Scanner(System.in);
System.out.print(“1.Enter Host Name \n2.Enter IP address \nChoice=“);
int choice = ch.nextInt();
if(choice==1)
{
Scanner input = new Scanner(System.in);
System.out.print(“\n Enter host name: “);
host = input.nextLine();
try {
InetAddress address = InetAddress.getByName(host);
System.out.println(“IP address: “ + address.getHostAddress());
System.out.println(“Host name : “ + address.getHostName());
System.out.println(“Host name and IP address: “ + address.toString());
}
catch (UnknownHostException ex) {
System.out.println(“Could not find “ + host);
}
}
else
{
Scanner input = new Scanner(System.in);
System.out.print(“\n Enter IP address: “);
host = input.nextLine();
try {
InetAddress address =
InetAddress.getByName(host);
System.out.println(“Host name : “ +
address.getHostName());
System.out.println(“IP address: “ +
address.getHostAddress());
System.out.println(“Host name and IP address: “ +
address.toString());

}
catch (UnknownHostException ex) {
System.out.println(“Could not find “ + host);
}
}

}
/*OUTPUT
iotlab@iotlab-Veriton-M200-B360:~$ javac IPDemo.java
iotlab@iotlab-Veriton-M200-B360:~$ java IPDemo
1.Enter Host Name
2.Enter IP address
Choice=1

Enter host name: www.google.com


IP address: 172.217.160.196
Host name : www.google.com
Host name and IP address: www.google.com/172.217.160.196
iotlab@iotlab-Veriton-M200-B360:~$ java IPDemo
1.Enter Host Name
2.Enter IP address
Choice=2

Enter IP address: 8.8.8.8


Host name : dns.google
IP address: 8.8.8.8
Host name and IP address: dns.google/8.8.8.8
iotlab@iotlab-Veriton-M200-B360:~$
*/
Conclusion -
We were able to convert a Host name to IP address and
also an IP address to Host name

You might also like