Skip to content

Instantly share code, notes, and snippets.

@apal21
Last active October 28, 2019 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apal21/3511062cd08ee8ac55dbaf54fdf3ff1c to your computer and use it in GitHub Desktop.
Save apal21/3511062cd08ee8ac55dbaf54fdf3ff1c to your computer and use it in GitHub Desktop.
Minimal Javascript Module to handle Tor network programatically in Node.js.
const { spawn, exec } = require('child_process');
let tor;
const proxy = kill =>
new Promise(resolve => {
if (kill && tor) {
tor.stdin.pause();
tor.kill();
resolve('killed');
return;
}
tor = spawn('tor');
tor.stdout.on('data', function(msg) {
if (msg.toString().includes('100%')) {
exec(
'curl --socks5 127.0.0.1:9050 checkip.amazonaws.com',
(err, stdout, stderr) => {
resolve(stdout);
}
);
}
});
});
module.exports = proxy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment