gpt4 book ai didi

node.js - 问 : Hot to change Ip in request using tor-request npm

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:27 27 4
gpt4 key购买 nike

我正在尝试使用 tor 更改 Ip根据 Tor-Request Documentation,我应该能够简单地通过使用来做到这一点

newTorSession

但是ip没有改变。我的代码有什么问题?

var tr = require('tor-request');

requestIP();


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);
}
})
}

最佳答案

来自doc

You need to enable the Tor ControlPort if you want to programmatically refresh the Tor session (i.e., get a new proxy IP address) without restarting your Tor client.

因此您需要按照以下步骤启用 ControlPort,然后将该密码传递给 tor-request

tr.TorControlPort.password = 'PASSWORD'

关于node.js - 问 : Hot to change Ip in request using tor-request npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48134778/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com