I'm trying to make a Java domain scanner (I am bored, what do you expect? lol)
Yet whenever I try it, I get the error message:
So it must be the makeSocket() function thats going wrong - somewhere.
Here is the code:
Yet whenever I try it, I get the error message:
Code:
I/O Exception: "whois_server_here"
Here is the code:
Code:
import java.io.*;
import java.net.*;
public class DomainScanner {
static boolean endStream = false;
static String result;
static Socket whoSoc = null;
static PrintWriter out = null;
static BufferedReader in = null;
static String whoisServer;
static String[] domArray;
public static void main(String[] args) throws IOException{
if(args.length == 0){
giveHelp();
}else if(args[0] == "/?"){
giveHelp();
}
whoisServer = args[0];
splitDomains(args[1]);
}
public static void splitDomains(String domains) throws IOException{
domArray = domains.split(",");
int i = 0;
while(i < domArray.length){
if(queryDomain(domArray[i]) == true){
System.out.println(domArray[i]);
}
i++;
}
}
public static boolean queryDomain(String domain) throws IOException{
makeSocket();
out.println(domain);
while(endStream == false){
String line = in.readLine();
if(result == null){
result = line;
}else{
result = result + "\r\n" + line;
}
if(line == null){
endStream = true;
}
}
closeSocket();
if((result.indexOf("NOT FOUND") != -1)|(result.indexOf("No Record") != -1)|(result.indexOf("No Match") != -1)){
return true;
}else{
return false;
}
}
public static void giveHelp(){
System.out.println("Syntax: java DomainScanner whois_server domain1,domain2,domain3");
System.exit(0);
}
public static void makeSocket(){
try{
whoSoc = new Socket(whoisServer, 42);
out = new PrintWriter(whoSoc.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(whoSoc.getInputStream()));
}catch(UnknownHostException e){
System.err.println("Unknown Host: \"" + whoisServer + "\"");
System.exit(1);
}catch (IOException e){
System.err.println("I/O Exception: \"" + whoisServer + "\"");
System.exit(1);
}
}
public static void closeSocket() throws IOException{
out.close();
in.close();
whoSoc.close();
}
}







