InetAddress address )
throws NetworkAdminException
{
try{
Socket socket = new Socket();
int timeout = TIMEOUT;
long start = SystemTime.getCurrentTime();
socket.connect( new InetSocketAddress( WHOIS_ADDRESS, WHOIS_PORT ), timeout );
long end = SystemTime.getCurrentTime();
timeout -= (end - start );
if ( timeout <= 0 ){
throw( new NetworkAdminException( "Timeout on connect" ));
}else if ( timeout > TIMEOUT ){
timeout = TIMEOUT;
}
socket.setSoTimeout( timeout );
try{
OutputStream os = socket.getOutputStream();
String command = "-u -p " + address.getHostAddress() + "\r\n";
os.write( command.getBytes());
os.flush();
InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
String result = "";
while( true ){
int len = is.read( buffer );
if ( len <= 0 ){
break;
}
result += new String( buffer, 0, len );
}
return( processResult( result ));
}finally{
socket.close();
}
}catch( Throwable e ){
throw( new NetworkAdminException( "whois connection failed", e ));
}