Skip to content

Instantly share code, notes, and snippets.

@Yengas
Created March 11, 2014 22:21
Show Gist options
  • Save Yengas/9496344 to your computer and use it in GitHub Desktop.
Save Yengas/9496344 to your computer and use it in GitHub Desktop.
Java WHOIS protocol with TCP
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
public class Whois {
public static void main(String[] args) throws Exception {
String domain = args.length > 0 ? args[0] : "domain";
InetAddress address = InetAddress.getByName("whois.internic.net");
Socket socket = new Socket(address, 43);
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
socket.getOutputStream().write((domain + "\r\n").getBytes());
String cevap = null;
while((cevap = br.readLine()) != null){ System.out.println(cevap); }
socket.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment