Advertisement
Eternoseeker

ass6dnslookup

Jun 7th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | Source Code | 0 0
  1. import java.net.*;
  2. import java.util.*;
  3.  
  4. public class ass6dnslookup {
  5.     public static void main(String[] args) {
  6.         String host;
  7.         Scanner ch = new Scanner(System.in);
  8.         System.out.print("1.Enter Host Name \n2.Enter IP address\nChoice=");
  9.         int choice = ch.nextInt();
  10.         if (choice == 1) {
  11.             Scanner input = new Scanner(System.in);
  12.             System.out.print("\n Enter host name: ");
  13.             host = input.nextLine();
  14.             try {
  15.                 InetAddress address = InetAddress.getByName(host);
  16.                 System.out.println("IP address: " + address.getHostAddress());
  17.                 System.out.println("Host name : " + address.getHostName());
  18.                 System.out.println("Host name and IP address: " +
  19.                         address.toString());
  20.             } catch (UnknownHostException ex) {
  21.                 System.out.println("Could not find " + host);
  22.             }
  23.         } else {
  24.             Scanner input = new Scanner(System.in);
  25.             System.out.print("\n Enter IP address: ");
  26.             host = input.nextLine();
  27.             try {
  28.                 InetAddress address = InetAddress.getByName(host);
  29.                 System.out.println("Host name : " + address.getHostName());
  30.                 System.out.println("IP address: " + address.getHostAddress());
  31.                 System.out.println("Host name and IP address: " +
  32.                         address.toString());
  33.             } catch (UnknownHostException ex) {
  34.                 System.out.println("Could not find " + host);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement