Last active
October 28, 2019 18:14
-
-
Save apal21/3511062cd08ee8ac55dbaf54fdf3ff1c to your computer and use it in GitHub Desktop.
Minimal Javascript Module to handle Tor network programatically in Node.js.
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
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