external-ip
Advanced tools
Comparing version 0.0.1 to 0.0.2
10
index.js
@@ -10,4 +10,6 @@ 'use strict'; | ||
exec: function (i, stop, next) { | ||
providers[i](function (err, ip) { | ||
providers[i].getIP(function (err, ip) { | ||
if (err) { | ||
err = providers[i].url + ' : ' + err; | ||
console.log(err); | ||
errors.push(err); | ||
@@ -21,9 +23,5 @@ next(); | ||
done: function (ip) { | ||
if (! ip) { | ||
cb(errors, null); | ||
} else { | ||
cb(null, ip); | ||
} | ||
cb.apply(null, ip ? [null, ip] : [errors, null]); | ||
} | ||
}); | ||
}; |
'use strict'; | ||
/* | ||
curlmyip.com, ifconfig.me/ip, ifconfig.co | ||
*/ | ||
var request = require('request'); | ||
var utils = require('./utils'); | ||
// Check: https://github.com/mjhasbach/MOIRA | ||
var providers = [ | ||
'http://ifconfig.co/x-real-ip', | ||
'http://ifconfig.me/ip', | ||
'http://icanhazip.com/', | ||
'http://ip.appspot.com/', | ||
'http://curlmyip.com/', | ||
'http://ident.me/', | ||
'http://whatismyip.akamai.com/', | ||
'http://tnx.nl/ip', | ||
'http://myip.dnsomatic.com/', | ||
'http://ipecho.net/plain' | ||
]; | ||
var validate = function (provider) { | ||
var addValidation = function (provider) { | ||
return function (cb) { | ||
@@ -15,8 +27,5 @@ provider(function (err, body) { | ||
} | ||
body = body.replace('\n', ''); | ||
return cb.apply(null, utils.isIP(body) ? [null, body] : [new Error('Invalid IP'), null]); | ||
body = body.replace('\n', ''); | ||
if (utils.isIP(body)) { | ||
return cb(null, body); | ||
} | ||
cb(new Error('Invalid IP'), null); | ||
}); | ||
@@ -26,34 +35,21 @@ }; | ||
// flaky | ||
var curlmyipCom = function (cb) { | ||
var url = 'http://curlmyip.com'; | ||
request.get(url, function (err, res, body) { | ||
cb.apply(null, err ? [new Error(url + ': ' + err), null] : [null, body]); | ||
}); | ||
var requestFactory = function (url) { | ||
return function (cb) { | ||
request.get({ | ||
'url': url, | ||
headers: { | ||
'User-Agent': 'curl/' | ||
} | ||
}, function (err, res, body) { | ||
cb.apply(null, err ? [err, null] : [null, body]); | ||
}); | ||
}; | ||
}; | ||
// slow | ||
var ifconfigMe = function (cb) { | ||
var url = 'http://ifconfig.me/ip'; | ||
request.get(url, function (err, res, body) { | ||
cb.apply(null, err ? [new Error(url + ': ' + err), null] : [null, body]); | ||
}); | ||
}; | ||
// Most reliable | ||
var ifconfigCo = function (cb) { | ||
var url = 'http://ifconfig.co/x-real-ip'; | ||
// Trick the server that we are using curl so it wont sent html | ||
request.get({ | ||
'url': url, | ||
headers: { | ||
'User-Agent': 'curl/' | ||
} | ||
}, function (err, res, body) { | ||
cb.apply(null, err ? [new Error(url + ': ' + err), null] : [null, body]); | ||
}); | ||
}; | ||
module.exports = [ifconfigCo, ifconfigMe, curlmyipCom].map(function (provider) { | ||
return validate(provider); | ||
module.exports = providers.map(function (url) { | ||
return { | ||
getIP: addValidation(requestFactory(url)), | ||
url: url | ||
}; | ||
}); |
{ | ||
"name": "external-ip", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Get your external IP, with fallbacks", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
internal-ip |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6570
145
1