1 16 package examples; 17 18 import java.io.IOException ; 19 import java.net.InetAddress ; 20 import java.net.UnknownHostException ; 21 import org.apache.commons.net.WhoisClient; 22 23 28 public final class fwhois 29 { 30 31 public static final void main(String [] args) 32 { 33 int index; 34 String handle, host; 35 InetAddress address = null; 36 WhoisClient whois; 37 38 if (args.length != 1) 39 { 40 System.err.println("usage: fwhois handle[@<server>]"); 41 System.exit(1); 42 } 43 44 index = args[0].lastIndexOf("@"); 45 46 whois = new WhoisClient(); 47 whois.setDefaultTimeout(60000); 49 50 if (index == -1) 51 { 52 handle = args[0]; 53 host = WhoisClient.DEFAULT_HOST; 54 } 55 else 56 { 57 handle = args[0].substring(0, index); 58 host = args[0].substring(index + 1); 59 } 60 61 try 62 { 63 address = InetAddress.getByName(host); 64 } 65 catch (UnknownHostException e) 66 { 67 System.err.println("Error unknown host: " + e.getMessage()); 68 System.exit(1); 69 } 70 71 System.out.println("[" + address.getHostName() + "]"); 72 73 try 74 { 75 whois.connect(address); 76 System.out.print(whois.query(handle)); 77 whois.disconnect(); 78 } 79 catch (IOException e) 80 { 81 System.err.println("Error I/O exception: " + e.getMessage()); 82 System.exit(1); 83 } 84 } 85 86 } 87 | Popular Tags |