import java.net.URL;
import java.net.HttpURLConnection;
import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.ArrayList;
import java.net.*;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.JavaScriptPage;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.HttpMethod;
//import sun.misc.Base64;
public class Socks5Test {
private URLConnection uc;
public void connect() {
try {
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "http://92.241.164.47");
System.setProperty("http.proxyPort", "23235");
URL url=new URL("http://92.241.164.47");
uc = url.openConnection ();
String encoded = new String(Base64.encodeBytesToBytes(new String("u298:9wmo6fur").getBytes()));
uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
uc.connect();
} catch(Exception e) {
} finally {
}
}
public static void main(String[] args) {
try {
try {
System.out.println("Proxy an?: " + System.getProperty("http.proxySet"));
System.out.println("Host: " + System.getProperty("http.proxyHost"));
System.out.println("Port: " + System.getProperty("http.proxyPort"));
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "http://92.241.164.47");
System.setProperty("http.proxyPort", "23235");
Authenticator.setDefault(new ProxyAuth());
}catch(SecurityException e) {
e.printStackTrace();
}catch(NullPointerException e) {
e.printStackTrace();
}
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);
webClient.setJavaScriptEnabled(true);
webClient.setCssEnabled(true);
WebRequest request = new WebRequest(new URL("http://92.241.164.47"));
request.setProxyHost("92.241.164.47");
request.setProxyPort(23235);
request.setSocksProxy(true);
request.setHttpMethod(HttpMethod.GET);
System.out.println(request.getUrl());
System.out.println("RequestParameter: " + request.getRequestParameters());
System.out.println("Charset: " + request.getCharset());
System.out.println("ProxyHost: " + request.getProxyHost());
WebResponse antwort = webClient.getWebConnection().getResponse(request);
System.out.println(antwort.getStatusCode());
System.out.println(antwort.getContentAsString());
} catch(Exception e) {
}
}
}
class ProxyAuth extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
System.out.printf( "Request by: url=%s, host=%s, site-IP=%s, port=%s%n",
getRequestingURL(), getRequestingHost(),
getRequestingSite(), getRequestingPort() );
String user = "u298";
String pwd = "9wmo6fur";
return(new PasswordAuthentication(user, pwd.toCharArray()));
}
}