Replies: 1 comment
-
Requirements:
const got = require("got");
const spawn = require("cross-spawn");
const { SocksProxyAgent } = require("socks-proxy-agent");
// Launch a TOR proxy via Docker
// @see https://github.com/osminogin/docker-tor-simple
const proxy = spawn("docker", [
...["run", "--rm", "-i", "-a", "stdout"],
...["-p", "127.0.0.1:9050:9050/tcp"],
...["osminogin/tor-simple:latest"],
]);
// Wait until the socks5 proxy server is up and running
proxy.stdout.on("data", (data) => {
process.stderr.write(data);
if (data.toString().includes("Opened Socks listener")) {
run().finally(() => proxy.kill("SIGINT"));
}
});
// Configure an HTTP client using socks5 proxy
const client = got.extend({
agent: {
https: new SocksProxyAgent("socks5://localhost:9050"),
},
});
// TODO: Write some code that requires a proxy
async function run() {
const body = await client.get("https://jsonip.com/").json();
console.log("Client IP:", body.ip);
} Source: https://dev.to/koistya/run-node-js-scripts-from-under-a-tor-http-proxy-b1 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an instance of TOR running on 127.0.0.1:9150.
How do I set GOT to proxy through it?
Beta Was this translation helpful? Give feedback.
All reactions