i have launched machine on amazon ec2 , have port 22 open world (so ssh machine allowed). created tunnel machine using:
/usr/bin/ssh -c -n -d '*:20022' -i <ssh_key_file> -o serveraliveinterval=20 -o serveralivecountmax=3 -o stricthostkeychecking=no -o userknownhostsfile=/dev/null ec2-user@ec2-a-b-c-d.compute-1.amazonaws.com
note above public dns.
the tunnel works fine, because i'm getting correct output when run curl command:
curl --proxy socks5h://127.0.0.1:20022 https://ec2-a-b-c-d.compute-1.amazonaws.com:<my_port>
however, i'm not able establish connection using java , httpurlconnection using same socks proxy. here's piece of code:
import sun.net.www.protocol.http.httpurlconnection; import java.net.inetsocketaddress; import java.net.proxy; import java.net.url; public static void main(string[] args) throws exception { string urlstring = "http://ec2-a-b-c-d.compute-1.amazonaws.com:<my_port>"; url url = new url(urlstring); proxy proxy = new proxy(proxy.type.socks, inetsocketaddress.createunresolved("127.0.0.1", 20022)); system.out.println("opening connection: " + url.tostring() + " proxy: " + proxy); httpurlconnection conn = (httpurlconnection) url.openconnection(proxy); conn.connect(); return 0; }
it times out following stack trace @ "conn.connect()" (line numbers not accurate)
exception in thread "main" java.net.socketexception: malformed reply socks server @ java.net.sockssocketimpl.readsocksreply(sockssocketimpl.java:129) @ java.net.sockssocketimpl.connect(sockssocketimpl.java:502) @ java.net.socket.connect(socket.java:579) @ java.net.socket.connect(socket.java:528) @ sun.net.networkclient.doconnect(networkclient.java:180) @ sun.net.www.http.httpclient.openserver(httpclient.java:432) @ sun.net.www.http.httpclient.openserver(httpclient.java:527) @ sun.net.www.http.httpclient.<init>(httpclient.java:211) @ sun.net.www.http.httpclient.new(httpclient.java:308) @ sun.net.www.http.httpclient.new(httpclient.java:326) @ sun.net.www.protocol.http.httpurlconnection.getnewhttpclient(httpurlconnection.java:997) @ sun.net.www.protocol.http.httpurlconnection.plainconnect(httpurlconnection.java:976) @ sun.net.www.protocol.http.httpurlconnection.connect(httpurlconnection.java:851) @ com.rajat.http_connection.httpconnection.run(httpconnection.java:53)
any idea why case?
Comments
Post a Comment