Luninariel

DNSClient0 - WIP

Oct 4th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. // import all necessary packages and classes
  2.  
  3. import java.net.InetAddress;
  4. import java.net.UnknownHostException;
  5.  
  6. public class DNSClient0 {
  7.     public static void main(String[] args) {
  8.         try {
  9.             // get the IP address of the local host
  10.             InetAddress inetAddress0 = InetAddress.getLocalHost();
  11.  
  12.             System.out.println("local host " + inetAddress0);
  13.  
  14.  
  15.             // resolve the IP address of missouriwestern.edu
  16.             InetAddress inetAddress1 = InetAddress.getByName("www.missouriwestern.edu");
  17.  
  18.  
  19.             // print the host name for the resolved address
  20.             System.out.println(inetAddress1.getHostName());
  21.  
  22.             // print the IP address in textual presentation
  23.             System.out.println(inetAddress1.getHostAddress());
  24.  
  25.             // resolve all IP addresses of amazon.com
  26.             InetAddress[] inetAddressArray0 = InetAddress.getAllByName("www.amazon.com");
  27.  
  28.  
  29.            for(int i=0; i<inetAddressArray0.length; i++) {
  30.             // print the host name for the resolved address
  31.            System.out.println(inetAddressArray0[i].getHostName());
  32.             // print each IP address mapped to amazon.com in textual presentation
  33.             System.out.println(inetAddressArray0[i].getHostAddress());
  34.           }
  35.         } catch (UnknownHostException unknownHostException0) {
  36.             System.out.println(unknownHostException0);
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment