Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Need help with some Java

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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
Close
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
Close
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
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back