Skip to content

Instantly share code, notes, and snippets.

@octavian-nita
Created August 22, 2014 09:48
Show Gist options
  • Select an option

  • Save octavian-nita/fd3cdb4a27964c8d2c08 to your computer and use it in GitHub Desktop.

Select an option

Save octavian-nita/fd3cdb4a27964c8d2c08 to your computer and use it in GitHub Desktop.
Callback on getting the current visible IP address in Node.js, using basic proxy authorization
'use strict';
var ip;
function visibleIp(callback) {
if (ip || (ip = process.env['VISIBLE_IP'])) {
return process.nextTick(function() { callback(null, ip); });
}
require('http').get({
host: 'proxyHost',
port: proxyPort,
path: 'http://cp.vu/show_my_ip',
headers: {
'Proxy-Authorization': 'Basic ' + new Buffer('username:password').toString('base64'),
Host: 'cp.vu'
}}, function(response) {
ip = '';
response.on('data', function(chunk) { ip += chunk; });
response.on('end', function() { callback(null, ip); });
}).on('error', function(error) { callback(error); }).end();
}
exports.visibleIp = visibleIp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment