How to get whois information using Java? - BunksAllowed

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

Community

demo-image

How to get whois information using Java?

Share This
WhoisFetching.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Happy Exploring!

Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.