FileDocCategorySizeDatePackage
Whois.javaAPI DocExample3702Sun Dec 12 10:53:02 GMT 2004None

Whois

public class Whois extends Object

Fields Summary
public static final int
DEFAULT_PORT
public static final String
DEFAULT_HOST
private int
port
private InetAddress
host
Constructors Summary
public Whois(InetAddress host, int port)


       
    this.host = host;
    this.port = port;     
  
public Whois(InetAddress host)

    this(host, DEFAULT_PORT);     
  
public Whois(String hostname, int port)

    this(InetAddress.getByName(hostname), port);     
  
public Whois(String hostname)

    this(InetAddress.getByName(hostname), DEFAULT_PORT);     
  
public Whois()

    this(DEFAULT_HOST, DEFAULT_PORT);     
  
Methods Summary
public java.net.InetAddressgetHost()

    return this.host;     
  
public java.lang.StringlookUpNames(java.lang.String target, Whois$SearchFor category, Whois$SearchIn group, boolean exactMatch)

      
    String suffix = "";
    if (!exactMatch) suffix = ".";
  
    String searchInLabel  = "";
    String searchForLabel = "";
    
    if (group == SearchIn.ALL) searchInLabel = "";
    else if (group == SearchIn.NAME) searchInLabel = "Name ";
    else if (group == SearchIn.MAILBOX) searchInLabel = "Mailbox ";
    else if (group == SearchIn.HANDLE) searchInLabel = "!";
    
    if (category == SearchFor.NETWORK) searchForLabel = "Network ";
    else if (category == SearchFor.PERSON) searchForLabel = "Person ";
    else if (category == SearchFor.HOST) searchForLabel = "Host ";
    else if (category == SearchFor.DOMAIN) searchForLabel = "Domain ";
    else if (category == SearchFor.ORGANIZATION) {
      searchForLabel = "Organization ";
    }
    else if (category == SearchFor.GROUP) searchForLabel = "Group ";
    else if (category == SearchFor.GATEWAY) {
      searchForLabel = "Gateway ";
    }
    else if (category == SearchFor.ASN) searchForLabel = "ASN ";
    
    String prefix = searchForLabel + searchInLabel;
    String query = prefix + target + suffix;
        
    Socket theSocket = new Socket(host, port);
    Writer out 
     = new OutputStreamWriter(theSocket.getOutputStream(), "ASCII");
    SafeBufferedReader in = new SafeBufferedReader(new 
     InputStreamReader(theSocket.getInputStream(), "ASCII"));
    out.write(query + "\r\n");
    out.flush();
    StringBuffer response = new StringBuffer();
    String theLine = null;
    while ((theLine = in.readLine()) != null) {
      response.append(theLine);
      response.append("\r\n");
    }
    theSocket.close();
    
    return response.toString();

  
public voidsetHost(java.lang.String host)

    this.host = InetAddress.getByName(host);