A Simple whois program in Java

By: Henry  

The very simple example that follows opens a connection to a "whois" port on the InterNIC server, sends the command-line argument down the socket, and then prints the data that is returned. InterNIC will try to look up the argument as a registered Internet domain name, then send back the IP address and contact information for that site.

//Demonstrate Sockets.
import java.net.*;
import java.io.*;
class Whois {
public static void main(String args[]) throws Exception {
int c;
Socket s = new Socket("internic.net", 43);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
String str = (args.length == 0 ? "starwave-dom" : args[0]) +
byte buf[] = str.getBytes();
while ((c = in.read()) != -1) {
System.out.print((char) c);

Try different domain names and see how the results change.

This tutorial is an extract from the "The Complete Reference Part 2 by Herbert Schildt".

Archived Comments

Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial