Dynadot โ€” .com Registration $8.99

Need help with some Java

Spaceship Spaceship
Watch

Barrucadu

Established Member
Impact
64
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:
Code:
I/O Exception: "whois_server_here"
So it must be the makeSocket() function thats going wrong - somewhere.

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();
     }
}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You could read which line the error is coming from, right? :o
 
0
•••
klarth said:
You could read which line the error is coming from, right? :o

Err.. yes
Code:
          }catch (IOException e){
               System.err.println("I/O Exception: \"" + whoisServer + "\"");
               System.exit(1);
          }
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back