Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

external-ip

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

external-ip - npm Package Compare versions

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]);
}
});
};

72

lib/providers.js
'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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc