Thursday, August 29, 2019

9. Write a program for DNS lookup. Given an IP address input, it should return URL and vice- versa.

Download The write up here

/import java.net.*;
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:~$ 
*/

2 comments:

  1. Hey! please stop scrolling now. I love your content it's very useful and I want your 1 minute attention for my amazing products. We provide Intelligent switch and more European socket along with these more items:
    Wall switch manufacturer
    Switch socket manufacturer
    Wall switch factory
    Socket factory
    I must say you gonna love them. please have a look once on our official website too

    ReplyDelete

13. Configure RIP/OSPF/BGP using packet Tracer.

Download writeup here Fig: OSPF Protocol Configuration OSPF Router 0 Configureation Router>e...