Created
March 2, 2024 08:23
-
-
Save Densamisten/f61ff7788ba709e1577400df7641a519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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