initial import
authorHansjürg Wenger <hansjuerg.wenger@bfh.ch>
Tue, 14 May 2013 08:39:20 +0000 (08:39 +0000)
committerHansjürg Wenger <hansjuerg.wenger@bfh.ch>
Tue, 14 May 2013 08:39:20 +0000 (08:39 +0000)
DNSqueries.class [new file with mode: 0644]
DNSqueries.java [new file with mode: 0644]

diff --git a/DNSqueries.class b/DNSqueries.class
new file mode 100644 (file)
index 0000000..4d11988
Binary files /dev/null and b/DNSqueries.class differ
diff --git a/DNSqueries.java b/DNSqueries.java
new file mode 100644 (file)
index 0000000..7be72bb
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * (c) 2010 WGH1@BFH
+ *
+ * shows how to use the DNS resolver library within java
+ *
+ */
+
+// Import the Scanner class
+import java.util.Scanner;
+// Import the InetAddress class
+import java.net.InetAddress;
+// Import the UnknownHostException class
+import java.net.UnknownHostException;
+
+public class DNSqueries {
+
+       public static void main(String[] args) {
+                
+               try {
+                       int i;
+                       Scanner s;
+                       // Internet Address
+                       InetAddress iAddr;
+                       // Array of Internet Addresses
+                       InetAddress[] iList;
+                       // Hostnames
+                       String inHostName, canHostName;
+
+                       // read in hostname or IP address 
+                       s = new Scanner(System.in);
+                       System.out.print("\nEnter Hostname or IP-Address: ");
+                       inHostName = s.next();
+
+                       // Determines the IP address of a host, given the host's name
+                       iAddr = InetAddress.getByName( inHostName );
+
+                       // Gets the fully qualified domain name for this IP address
+                       canHostName = iAddr.getCanonicalHostName();
+
+                       // Given the name of a host, returns an array of its IP addresses,
+                       // based on the configured name service on the system
+                       iList = InetAddress.getAllByName( canHostName );
+
+                       // Print out the FQDN
+                       System.out.println("\nCanonical Hostname: " + iAddr.getCanonicalHostName() + "\n");
+
+                       // Print out ..
+                       for (i=0;i<iList.length;i++) {
+                               //                 .. FQDN ..
+                               System.out.println("Hostname " + i + ": " + iList[i].getCanonicalHostName() +
+                               //                 .. and address
+                                                  "  Address " + i + ": " + iList[i].getHostAddress() );
+                       }
+                       System.out.println();
+               }
+               // Exception handler
+               catch (UnknownHostException exception) {
+                       System.err.println("\nHost unknown: " + exception.getMessage() + "\n");
+               }
+       }
+}