0

I have tried this...gives me a java.lang.IllegalArgumentException: Invalid Proxy. The getters populate the proxy and port from a text file.

    //Imports
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.net.*;
    import java.util.ArrayList;

    import org.apache.commons.net.whois.WhoisClient;

    public void  whoisCheck(String host) {
        SocketAddress addr = new InetSocketAddress(getProxy(), getPort)
        Proxy useProxy = new Proxy(Proxy.Type.HTTP, addr);

        WhoisClient whoisClient = new WhoisClient();
        whoisClient.setProxy(useProxy);
        whoisClient.connect(IANA_WHOIS_SERVER, WHOIS_PORT);
        tmpStr = whoisClient.query(host);
        whoisClient.disconnect();
    }
try-catch-finally
  • 7,436
  • 6
  • 46
  • 67
Mallik Kumar
  • 540
  • 1
  • 5
  • 28
  • There are vital parts missing in your question: the imports and a link to the WhoisClient library. – try-catch-finally Jun 21 '14 at 11:32
  • Since `setProxy()` [can't throw](http://grepcode.com/file/repo1.maven.org/maven2/commons-net/commons-net/3.3/org/apache/commons/net/SocketClient.java#822) it's logical that `new Proxy()` throws this (I've to guess since you didn't say where the exception is thrown). Looking into [Proxy's API docs](http://docs.oracle.com/javase/6/docs/api/java/net/Proxy.html#Proxy%28java.net.Proxy.Type,%20java.net.SocketAddress%29) we can see that "`IllegalArgumentException - when the type and the address are incompatible`". What's the address returned by `getProxy()`? – try-catch-finally Jun 21 '14 at 13:18
  • The error is thrown at whoisClient.connect(IANA_WHOIS_SERVER, WHOIS_PORT); The address returned is 23.19.34.15 and port is 8800 – Mallik Kumar Jun 21 '14 at 13:31

1 Answers1

-1

whois is a protocol running over TCP port 43, not over HTTP/HTTPS. It has no concept of proxies.

For these two reasons, do not use an HTTP library to connect to whois servers, as this will never work correctly out of the box. You will create yourself too many problems. Instead, either use a specific whois library in your programming language, or just go basically opening a TCP socket on port 43, writing on it your query, finishing by CR+LF and reading back the server's reply as a blob of text.

If you need to hide your IP address, you need to resort to typical IP level “redirections” like a tunnel, or a SOCKS library.

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54