i'm trying to change Ip by using tor
According to Tor-Request Documentation I should be able to do this simply by using
newTorSession
But ip not changing. What is wrong in my code?
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);
}
})
}
From the 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.
so you need to follow these steps to enable ControlPort then pass that password to tor-request
tr.TorControlPort.password = 'PASSWORD'
Related
I use node.js to make requests on google.
I used puppeteer but he detected my robot.
so i used tor-request.
I can change my ip at each connection.
But google still hangs with the same error message.
I want to change the user-agent of the tor-expert bundle.
How to do ?
Our systems have detected unusual traffic from your computer network.
Please try your request again later. Why did this happen?
IP address: 109.70.100.** Time: 2019-08-03T08:47:17Z URL:
https://www.google.com/search?q=re&gbv=1&sei=6UlFXY6mKsSiab3EjbAF
var tr = require('tor-request');
tr.TorControlPort.password = "***";
io.sockets.on('connection', async(socket) => {
socket.on('key', function(value) {
function torIp() {
tr.request('https://www.google.com/search?q=re&gbv=1&sei=6UlFXY6mKsSiab3EjbAF', function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Your public IP is: " + body);
}
socket.emit('google_web', body)
});
}
torIp();
tr.renewTorSession(function(error, msg) {
console.log(error);
console.log(msg);
if (msg) {
torIp();
}
});
})
})
To change the user agent, you can use the method described here, a tor-request issue:
tr.request({
url: 'https://www.google.com/search?q=re&gbv=1&sei=6UlFXY6mKsSiab3EjbAF',
headers: {
'user-agent': 'giraffe'
}
}, function(error, response, body) {
// ...
});
Just replace giraffe with whichever user agent you wish.
(But, as the comment noted, Google may well have blocked certain Tor exit nodes completely, in which case changing the user-agent won't help)
I have used the public-ip npm package to get the public IP address of the user, it is giving the same public IP address as in http://whatismyipaddress.com, but when using it in a Digital Ocean server it is giving me the Digital Ocean IP address instead of user's public IP address.
I have tried it on nodejs.
const publicIp = require('public-ip');
const ip = await publicIp.v4(); //to save ip in user
I want the public IP address of the user instead of getting the Digital Ocean IP address.
Just query https://api.ipify.org/
// web
let xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.ipify.org');
xhr.send();
xhr.onload = function() {
if (xhr.status != 200) {
console.log(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
} else { // show the result
console.log(xhr.response)
}
};
// nodejs
const https = require('https');
https.get('https://api.ipify.org', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data));
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
This function publicIp.v4() and public-ip module will help you get (detect) your public IP of server or computer that application's running on (not IP of user). And Digital Ocean returns value of its public IP is right.
In your case, you need to retrieve user's IP from user's request, it can be call remote client IP address. It's better for you to check this question Express.js: how to get remote client address
Hope it can help.
I am experimenting with the softlayer-client api wrapper in my Node Express application. My goal is to update the VPN password of a User_Customer by calling the updateVpnPassword method on a specific user.
I can construct a call to achieve a VPN password update using request, but I'm not sure it's the best way to achieve the desired result.
Can the softlayer-client module be used to make an similar call to this:
function updateVpnPassword(req, res, next) {
// Construct URL to update VPN
myURL = 'https://' + <userIDAdmin> + ':' + <apiKeyAdmin> + '#api.softlayer.com/rest/v3/SoftLayer_User_Customer/' + <softLayerID> + '/updateVpnPassword/' + <newPassword> + '.json';
request.get({url: myURL}, function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
next();
}
My initial attempts have been to try variations on this:
function updateVpnPassword(req, res, next) {
// Assuming var client = new SoftLayer();
client
.auth(<userIDAdmin>, <apiKeyAdmin>)
.path('User_Customer', <softLayerID>,'updateVpnPassword')
.parameters(<newPassword>)
.put(function(err,result){
console.log(result);
if (err) {
next(err); // Pass errors to Express.
}
else {
// update successful
}
});
next();
}
But the console log gives an error response like
{ message: { error: 'Internal Error', code: 'SoftLayer_Exception_Public' } }.
I expect a TRUE or FALSE response, to indicate the whether the update is successful.
A similar python client can be found here but I require an implementation in JS.
I'm not familiar with nodejs but I installed the package softlayer-node and run your second code and it worked.
I also created the following script and I got TRUE
var username = 'set me';
var apikey = 'set me';
var userId = 1111111;
var SoftLayer = require('softlayer-node');
var client = new SoftLayer();
client
.auth(username, apikey)
.path('User_Custome', userId, 'updateVpnPassword')
.parameters('P#ssword123')
.put()
.then(function(result) {
console.log(result);
}, function(error) {
console.log(error);
});
node command:
$ node updateVpnPassword.js
true
Did you tried by sending that request using curl or any other REST client like postman?
If you get the same error then I recommend you submit a ticket and provide information like the id of users you are trying to update the vpn password and the user with which you are sending the request.
i'm trying to get client hostname by getting their ip and then use dns.reverse to do the thing, it works, i'm getting the ip but i don't client hostname. Am i misunderstand something or is there the better way to do.
queue2: function(req, res){
var mac = req.param('mac');
var ip = req.connection.remoteAddress;
dns.lookup(ip,function onLookup(err, addresses){
console.log('Address :' + addresses);
dns.reverse(addresses, function(err, hostname){
Q_list.query("CALL GetQueuePlay('00')", function (err, result) {
if (err){
return res.send(err);
}
console.log(result);
console.log(addresses+ ' : ' + JSON.stringify(hostname));
return res.view('kue/kue',{q_play_list:result});
});
});
});
},
So for unit testing I need to redirect a domain to a new IP for a specific machine. I've setup a route in node to update the machine's hosts file.
exports.hosts = function hosts(req, res) {
var domain = req.params.domain;
var ip = req.params.ip;
if (domain === 'localhost') {
res.json(500, {message: 'invalid domain'});
return;
}
async.waterfall([
function (callback) {
fs.readFile('/etc/hosts', callback);
},
function (data, callback) {
// Remove existing entry
var lines = data.toString().split('\n');
data = '';
for (var line in lines) {
if (!_str.endsWith(lines[line], domain) && lines[line]) {
data += lines[line] + '\n';
}
}
callback(null, data);
},
function (data, callback) {
if (ip) {
data += ip + ' ' + domain + '\n';
}
callback(null, data);
},
function (data, callback) {
fs.writeFile('/etc/hosts', data, callback);
}
],
function (err) {
if (err) {
res.json(500, err);
} else {
res.send(200);
}
});
};
The edit works fine. The issue is that I the next call to the domain from the node process still goes to the last IP address. If I restart Node it sees the new IP address in the hosts file.
How can I get Node to see the updated hosts file without restarting the process?
I know this is late, but I imagine that similar to environment variables, hosts file info may be loaded and cached. By the same token you must restart software for those new env variables to be noticed, you may need to kill the node process and restart it to get the new hosts entry. If you install something like pm2, you would adjust your initial kickoff command slightly: pm2 start app.js instead of node app.js. Then every time you update your hosts file, kill your app and pm2 will restart it. Killing your app is as easy as process.kill(), process.exit(), or throw an Error.