Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Need help with some Java

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
NamecheapNamecheap
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
•••
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back