为什么 tor-request 不循环更新 ip
Why tor-request dont't update ip in loop
我有以下代码:
var tr = require('tor-request');
tr.TorControlPort.password = '***'
tr.request('https://api.ipify.org', (err, resp, ip) => {
console.log('initial ip: ' + ip)
})
function torRequest() {
tr.renewTorSession((err, msg) => {
console.log(msg);
tr.request('https://api.ipify.org', (err, resp, ip) => {
console.log('ip: ' + ip)
})
})
}
torRequest();
for ( let i = 0; i < 2; i++) {
torRequest();
}
我的输出:
Tor session successfully renewed!!
Tor session successfully renewed!!
Tor session successfully renewed!!
ip: 46.165.245.154
ip: 46.165.245.154
ip: 46.165.245.154
initial ip: 176.10.107.180
当我多次调用 torRequest
时,所有请求都将 return 使用相同的 ip。是否可以在循环中运行它?
您需要明确刷新 tor 的会话
tr.newTorSession( (err) =>
{
requestIP();
return;
});
也加上这个
tr.setTorAddress('localhost', 9050);
之后
tr.TorControlPort.password = '***'
新的 TorSessio :
module.exports = {
// <snip>
/**
* Helper object to communicate with the tor ControlPort. Requires an enabled ControlPort on tor.
*/
TorControlPort: {
password: "", // default ControlPort password
host: "localhost", // default address
port: 9051, // default ControlPort
/**
* @param {Array.string} commands - signals that are sent to the ControlPort
*/
send: function (commands, done(err, data))
}
/**
* A set of predefined TorControlPort commands to request and verify tor for a new session (get a new ip to use).
*
* @param {function} done - the callback function to tell you when the process is done
* @param {object} err - null if tor session renewed successfully
*/
newTorSession: function ( done(err) ) // clears and renews the Tor session (i.e., you get a new IP)
}
就是这样..它会起作用..在我的情况下.. IP 将在 5-6 次后更新
祝你好运,'。
我有以下代码:
var tr = require('tor-request');
tr.TorControlPort.password = '***'
tr.request('https://api.ipify.org', (err, resp, ip) => {
console.log('initial ip: ' + ip)
})
function torRequest() {
tr.renewTorSession((err, msg) => {
console.log(msg);
tr.request('https://api.ipify.org', (err, resp, ip) => {
console.log('ip: ' + ip)
})
})
}
torRequest();
for ( let i = 0; i < 2; i++) {
torRequest();
}
我的输出:
Tor session successfully renewed!!
Tor session successfully renewed!!
Tor session successfully renewed!!
ip: 46.165.245.154
ip: 46.165.245.154
ip: 46.165.245.154
initial ip: 176.10.107.180
当我多次调用 torRequest
时,所有请求都将 return 使用相同的 ip。是否可以在循环中运行它?
您需要明确刷新 tor 的会话
tr.newTorSession( (err) =>
{
requestIP();
return;
});
也加上这个
tr.setTorAddress('localhost', 9050);
之后
tr.TorControlPort.password = '***'
新的 TorSessio :
module.exports = {
// <snip>
/**
* Helper object to communicate with the tor ControlPort. Requires an enabled ControlPort on tor.
*/
TorControlPort: {
password: "", // default ControlPort password
host: "localhost", // default address
port: 9051, // default ControlPort
/**
* @param {Array.string} commands - signals that are sent to the ControlPort
*/
send: function (commands, done(err, data))
}
/**
* A set of predefined TorControlPort commands to request and verify tor for a new session (get a new ip to use).
*
* @param {function} done - the callback function to tell you when the process is done
* @param {object} err - null if tor session renewed successfully
*/
newTorSession: function ( done(err) ) // clears and renews the Tor session (i.e., you get a new IP)
}
就是这样..它会起作用..在我的情况下.. IP 将在 5-6 次后更新
祝你好运,'。