You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tor Control Port: Error: connect ECONNREFUSED ::1:9051 #75
That being said, I tried it without and with setting a hashed password for the tor (according to README.md), and then I used tr.TorControlPort.password = '<my_pass>' to set the password.
In both cases, I received the same error when I tried:
tr.newTorSession(async function (err) {
if (!err) {
console.log('New Tor session created');
await wait(5000);
getIp();
} else {
console.log(err);
}
});
node version: 18.16.0
tor-request: 3.1.0
Tor version: 0.4.7.13.
When tor starts it will tell you which torrc file it is using, please make sure it's the correct one.
e.g.
I've tested with npm run test-control-port (and configuring the correct port and password in the test/test-control-port.js file beforehand that matches my configured torrc file) and it's working correctly.
CLI output of tor running :
tor -f torrc
Oct 17 13:13:07.765 [notice] Tor 0.4.8.7 (git-bf5e234d44e73127) running on Windows 8 [or later] with Libevent 2.1.12-stable, OpenSSL 3.0.11, Zlib 1.3, Liblzma N/A, Libzstd N/A and Unknown N/A as libc.
Oct 17 13:13:07.765 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Oct 17 13:13:07.796 [notice] Read configuration file "D:\Faiz\Backend\Test_puppeteer\tor\tor\torrc".
Oct 17 13:13:07.796 [warn] Path for GeoIPFile () is relative and will resolve to D:\Faiz\Backend\Test_puppeteer\tor\tor<default>. Is this what you wanted?
Oct 17 13:13:07.796 [warn] Path for GeoIPv6File () is relative and will resolve to D:\Faiz\Backend\Test_puppeteer\tor\tor<default>. Is this what you wanted?
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9050
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9050
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9052
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9052
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9053
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9053
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9054
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9054
Oct 17 13:13:07.796 [notice] Opening Control listener on 127.0.0.1:9051
Oct 17 13:13:07.796 [notice] Opened Control listener connection (ready) on 127.0.0.1:9051
Oct 17 13:13:07.000 [notice] Bootstrapped 0% (starting): Starting
Oct 17 13:13:09.000 [notice] Starting with guard context "default"
Oct 17 13:13:10.000 [notice] Bootstrapped 5% (conn): Connecting to a relay
Oct 17 13:13:10.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Oct 17 13:13:10.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Oct 17 13:13:10.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Oct 17 13:13:10.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Oct 17 13:13:10.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Oct 17 13:13:10.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Oct 17 13:13:11.000 [notice] Bootstrapped 100% (done): Done
function requestIP() {
tr.request("https://api.ipify.org", function (err, res, body) {
if (!err && res.statusCode == 200) {
console.log("Your public (through Tor) IP is: " + body);
}
});
}
@FaizKEverestek another way to reset the tor session is by restarting the tor client (which is helpful to know) -- this doesn't look like an issue with tor-request specifically
@FaizKEverestek it seems like your tor ControlPort is running on 127.0.0.1:5051 while the library is trying to connect on ::1:5051 (which is the ipv6 version of the loopback address) -- I don't think they are equivalent but I'm not sure -- tr.TorControlPort.host = '127.0.0.1' looks like it had some hope of working but unsure
// Tor ControlPort configuration
const torControlPortHost = "127.0.0.1"; // IPv4 address
const torControlPortPort = 9051; // ControlPort port
const torControlPortPassword = "password"; // Replace with your actual ControlPort password
// Function to send commands to the Tor ControlPort
function renewTorConnection() {
const client = net.connect(
{
host: torControlPortHost,
port: torControlPortPort,
},
() => {
console.log("Connected to Tor ControlPort");
// Send the commands to authenticate and request a new identity
client.write(
`authenticate "${torControlPortPassword}"\nsignal newnym\nquit\n`
);
}
);
client.on("data", (data) => {
console.log("Received from Tor ControlPort:", data.toString());
client.end();
});
client.on("end", () => {
console.log("Disconnected from Tor ControlPort");
});
client.on("error", (err) => {
console.error("Error connecting to Tor ControlPort:", err);
});
}
// Export the function as renewTorConnection
module.exports = renewTorConnection;
Activity
Fa1z-khan commentedon Oct 17, 2023
+1
talmobi commentedon Oct 17, 2023
@aghArdeshir @FaizKEverestek
Hello
You have most likely configured your tor control port incorrectly and/or edited the wrong torrc file -- please check the README in this section: https://github.com/talmobi/tor-request#optional-configuring-tor-enabling-the-controlport
When tor starts it will tell you which torrc file it is using, please make sure it's the correct one.
e.g.

I've tested with
npm run test-control-port(and configuring the correct port and password in thetest/test-control-port.jsfile beforehand that matches my configuredtorrcfile) and it's working correctly.Fa1z-khan commentedon Oct 17, 2023
My torrc file :
SocksPort 127.0.0.1:9050
SocksPort 127.0.0.1:9052
SocksPort 127.0.0.1:9053
SocksPort 127.0.0.1:9054
ControlPort 127.0.0.1:9051
HashedControlPassword 16:D3F51F03E9A976FD60DC709D47A7AECCF051F0D0231144E4CD89F96844
CLI output of tor running :
tor -f torrc
Oct 17 13:13:07.765 [notice] Tor 0.4.8.7 (git-bf5e234d44e73127) running on Windows 8 [or later] with Libevent 2.1.12-stable, OpenSSL 3.0.11, Zlib 1.3, Liblzma N/A, Libzstd N/A and Unknown N/A as libc.
Oct 17 13:13:07.765 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Oct 17 13:13:07.796 [notice] Read configuration file "D:\Faiz\Backend\Test_puppeteer\tor\tor\torrc".
Oct 17 13:13:07.796 [warn] Path for GeoIPFile () is relative and will resolve to D:\Faiz\Backend\Test_puppeteer\tor\tor<default>. Is this what you wanted?
Oct 17 13:13:07.796 [warn] Path for GeoIPv6File () is relative and will resolve to D:\Faiz\Backend\Test_puppeteer\tor\tor<default>. Is this what you wanted?
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9050
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9050
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9052
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9052
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9053
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9053
Oct 17 13:13:07.796 [notice] Opening Socks listener on 127.0.0.1:9054
Oct 17 13:13:07.796 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9054
Oct 17 13:13:07.796 [notice] Opening Control listener on 127.0.0.1:9051
Oct 17 13:13:07.796 [notice] Opened Control listener connection (ready) on 127.0.0.1:9051
Oct 17 13:13:07.000 [notice] Bootstrapped 0% (starting): Starting
Oct 17 13:13:09.000 [notice] Starting with guard context "default"
Oct 17 13:13:10.000 [notice] Bootstrapped 5% (conn): Connecting to a relay
Oct 17 13:13:10.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Oct 17 13:13:10.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Oct 17 13:13:10.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Oct 17 13:13:10.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Oct 17 13:13:10.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Oct 17 13:13:10.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Oct 17 13:13:11.000 [notice] Bootstrapped 100% (done): Done
yes it's using the correct file
Fa1z-khan commentedon Oct 17, 2023
The code i'm trying to run :
var tr = require("tor-request");
requestIP();
tr.TorControlPort.password = "password";
tr.setTorAddress("localhost", 9050);
tr.newTorSession((err) => {
console.log(err);
requestIP();
return;
});
//console.log (tr.TorControlPort)
function requestIP() {
tr.request("https://api.ipify.org", function (err, res, body) {
if (!err && res.statusCode == 200) {
console.log("Your public (through Tor) IP is: " + body);
}
});
}
Fa1z-khan commentedon Oct 17, 2023
it works perfectly with the tr.request()
but has issues when it comes to tr.newTorSession()
talmobi commentedon Oct 17, 2023
@FaizKEverestek and what is the error you get?
Error: connect ECONNREFUSED ::1:9051?Fa1z-khan commentedon Oct 17, 2023
yep
PS D:\Faiz\Backend\Test_puppeteer> node request.js
Error: connect ECONNREFUSED ::1:9051
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 9051
}
Your public (through Tor) IP is: 185.220.100.253
talmobi commentedon Oct 17, 2023
@FaizKEverestek try setting
tr.TorControlPort.host = '::1'ortr.TorControlPort.host = '127.0.0.1'talmobi commentedon Oct 17, 2023
@FaizKEverestek and maybe try just using the port number 9051 in the torrc file instead of
127.0.0.1:9051Fa1z-khan commentedon Oct 17, 2023
yep i did that first didnt work
talmobi commentedon Oct 17, 2023
@FaizKEverestek another way to reset the tor session is by restarting the tor client (which is helpful to know) -- this doesn't look like an issue with
tor-requestspecificallytalmobi commentedon Oct 17, 2023
@FaizKEverestek it seems like your tor ControlPort is running on
127.0.0.1:5051while the library is trying to connect on::1:5051(which is the ipv6 version of the loopback address) -- I don't think they are equivalent but I'm not sure --tr.TorControlPort.host = '127.0.0.1'looks like it had some hope of working but unsureFa1z-khan commentedon Oct 17, 2023
i created my own solution which is working fine
Fa1z-khan commentedon Oct 17, 2023
const net = require("net");
// Tor ControlPort configuration
const torControlPortHost = "127.0.0.1"; // IPv4 address
const torControlPortPort = 9051; // ControlPort port
const torControlPortPassword = "password"; // Replace with your actual ControlPort password
// Function to send commands to the Tor ControlPort
function renewTorConnection() {
const client = net.connect(
{
host: torControlPortHost,
port: torControlPortPort,
},
() => {
console.log("Connected to Tor ControlPort");
);
client.on("data", (data) => {
console.log("Received from Tor ControlPort:", data.toString());
client.end();
});
client.on("end", () => {
console.log("Disconnected from Tor ControlPort");
});
client.on("error", (err) => {
console.error("Error connecting to Tor ControlPort:", err);
});
}
// Export the function as
renewTorConnectionmodule.exports = renewTorConnection;
followdarko commentedon Apr 23, 2024
Faced with the same problem. Confirmed
tr.TorControlPort.host = '127.0.0.1'solves issue