Advertisement
Guest User

NsLookup.java

a guest
Mar 26th, 2017
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.net.*;
  2. public class NsLookup {
  3. public static void main(String args[]) {
  4. if (args.length == 0) {
  5. System.out.println("Pemakaian: java NsLookup <hostname>");
  6. System.exit(0);
  7. }
  8. String host = args[0];
  9. InetAddress address = null;
  10. try {
  11. address = InetAddress.getByName(host);
  12. } catch(UnknownHostException e) {
  13. System.out.println("Unknown host");
  14. System.exit(0);
  15. }
  16. byte[] ip = address.getAddress();
  17. for (int i=0; i<ip.length; i++) {
  18. if (i > 0) System.out.print(".");
  19. System.out.print((ip[i]) & 0xff);
  20. }
  21. System.out.println();
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement