Skip to content

Instantly share code, notes, and snippets.

@Densamisten
Created March 2, 2024 08:23
Show Gist options
  • Select an option

  • Save Densamisten/f61ff7788ba709e1577400df7641a519 to your computer and use it in GitHub Desktop.

Select an option

Save Densamisten/f61ff7788ba709e1577400df7641a519 to your computer and use it in GitHub Desktop.
package net.kaupenjoe;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.URL;
import java.net.*;
// https://github.com/AsyncHttpClient/async-http-client/issues/1682#issuecomment-563389234
public class OkJavaOnionSocks {
public static String readInputStreamAsString(InputStream in)
throws IOException {
BufferedInputStream bis = new BufferedInputStream(in);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
byte b = (byte)result;
buf.write(b);
result = bis.read();
}
return buf.toString();
}
public static void main(String[] args) throws Exception {
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 9050));
URL url = new URL("http://check.torproject.org");
InputStream is=url.openConnection(proxy).getInputStream();
String string = readInputStreamAsString(is);
is.close();
System.out.println(string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment