How to get whois information using Java? - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

How to get whois information using Java?

Share This
WhoisFetching.java
import java.net.*; import java.io.*; public class WhoisFetching { public final static int DEFAULT_PORT = 43; public final static String DEFAULT_HOST = "whois.internic.net"; public static void main(String[] args) { InetAddress server; try { server = InetAddress.getByName(DEFAULT_HOST); } catch (UnknownHostException e) { System.err.println("Error: Could not locate default host " + DEFAULT_HOST); System.err.println("Check to make sure you're connected to the Internet and that DNS"); System.err.println("Usage: java WhoisFetching host port"); return; } int port = DEFAULT_PORT; try { Socket socket = new Socket(server, port); Writer out = new OutputStreamWriter(socket.getOutputStream(), "8859_1"); for (int i = 0; i < args.length; i++) out.write(args[i] + " "); out.write("\r\n"); out.flush(); InputStream raw = socket.getInputStream(); InputStream in = new BufferedInputStream(socket.getInputStream()); int c; while ((c = in.read()) != -1) System.out.write(c); } catch (IOException e) { System.err.println(e); } } }

Happy Exploring!

No comments:

Post a Comment