uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

ShowIP.java (587B)


      1 import java.net.*;
      2 
      3 public class ShowIP {
      4 	public static void main(String[] args) throws Exception {
      5 		InetAddress[] addr;
      6 		String hostname = "";
      7 
      8 		try {
      9 			hostname = args[0];
     10 			addr = InetAddress.getAllByName(hostname);
     11 
     12 			for (int i = 0; i < addr.length; i++)
     13 				System.out.println(i + "\t" + hostname + ": " +
     14 				    addr[i].toString());
     15 		} catch (ArrayIndexOutOfBoundsException e) {
     16 			System.err.println("usage: java ShowIP <hostname>");
     17 			System.exit(1);
     18 		} catch (UnknownHostException e) {
     19 			System.err.println("unknown host: " + hostname);
     20 			System.exit(1);
     21 		}
     22 	}
     23 }