import java.net.InetAddress; import java.net.UnknownHostException; /** * Program to perform simple functionality of NSLookUp (simple nslookup clone) * * @author sahir maredia (Kotia Solutions) * */ public class NSLookup { /** * @param args */ public static void main(String[] args) { if (args.length != 1) { System.out.println("Please provide valid arguments"); return; } try { InetAddress ipaddress = InetAddress.getByName(args[0]); System.out.println("Name : " + ipaddress.getHostName()); System.out.println("Address : " + ipaddress.getHostAddress()); } catch (UnknownHostException e) { System.out.println("Error occured : " + e.getMessage()); } } }
Run this program as follows:
sahir@sahir-laptop:~/networklab$ javac NSLookup.java
sahir@sahir-laptop:~/networklab$ java NSLookup google.com
Name : google.com
Address : 74.125.236.163
sahir@sahir-laptop:~/networklab$ java NSLookup 74.125.236.163
Name : maa03s16-in-f3.1e100.net
Address : 74.125.236.163
sahir@sahir-laptop:~/networklab$
sahir@sahir-laptop:~/networklab$ java NSLookup google.com
Name : google.com
Address : 74.125.236.163
sahir@sahir-laptop:~/networklab$ java NSLookup 74.125.236.163
Name : maa03s16-in-f3.1e100.net
Address : 74.125.236.163
sahir@sahir-laptop:~/networklab$
No comments:
Post a Comment