问:使用 Tor-request npm 在请求中更改 Ip 很热

how*_*elp 1 request tor node.js

我正在尝试使用 Tor 来更改 Ip 根据 Tor-Request 文档,我应该能够简单地使用

newTorSession
Run Code Online (Sandbox Code Playgroud)

但是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);
  }
})
}
Run Code Online (Sandbox Code Playgroud)

ufx*_*eng 5

文档

如果您想在不重新启动 Tor 客户端的情况下以编程方式刷新 Tor 会话(即获取新的代理 IP 地址),则需要启用 Tor ControlPort。

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

tr.TorControlPort.password = 'PASSWORD'
Run Code Online (Sandbox Code Playgroud)