Guest User

IPtoName.java

a guest
Apr 25th, 2017
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.net.*;
  2. public class IPtoName {
  3.     public static void main(String args[]) {
  4.         if (args.length == 0) {
  5.             System.out.println("Pemakaian: java IPtoName <IP address>");
  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("invalid IP - malformed IP");
  14.             System.exit(0);
  15.         }
  16.         System.out.println(address.getHostName());
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment