Comparing version 1.0.0 to 1.0.1
var request = require('request'); | ||
var foundIP = false; | ||
var completedRequests = 0; | ||
// List of IP reporting services | ||
// Criteria: URL returns an IP address ONLY in the response body | ||
var IPServices = [ | ||
var IPService = [ | ||
"http://ifconfig.me/ip", | ||
@@ -21,7 +22,7 @@ "http://icanhazip.com/", | ||
function getIP(callback) { | ||
for(var i = 0; i < IPServices.length; i++) { | ||
request(IPServices[i], function(error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
processIP(this.uri.href, body, callback); | ||
} | ||
for (var i = 0; i < IPService.length; i++) { | ||
request(IPService[i], function(error, response, body) { | ||
completedRequests += 1; | ||
if (error || response.statusCode != 200) {body = ""} | ||
handleResponse(this.uri.href, body, callback); | ||
}); | ||
@@ -32,8 +33,10 @@ } | ||
//Ensure only 1 callback is executed per getIP() call, validate IP address, then callback | ||
function processIP(IPService, address, callback) { | ||
if(!foundIP) { | ||
function handleResponse(service, address, callback) { | ||
if (!foundIP) { | ||
address = address.replace(/\s+/,""); | ||
if(isIP(address)) { | ||
if (isIP(address)) { | ||
foundIP = true; | ||
callback(address, IPService); | ||
callback(address, service, false); | ||
} else if (isLastRequest()) { | ||
callback(address, service, true); | ||
} | ||
@@ -55,2 +58,7 @@ } | ||
function isLastRequest() { | ||
return completedRequests == IPService.length | ||
} | ||
exports.getIP = getIP; |
{ | ||
"name": "moira", | ||
"description": "Most Outstanding IP Reporting Assistant", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/mjhasbach/MOIRA", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -18,13 +18,20 @@ > # MOIRA # | ||
Example (see test/test.js) | ||
var moira = require('moira'); | ||
moira.getIP(function(ip, service) { | ||
console.log("Your external IP address is " + ip); | ||
console.log("The fastest service to return your IP address was " + service); | ||
moira.getIP(function(ip, service, err) { | ||
if(!err) { | ||
console.log("Your external IP address is " + ip); | ||
console.log("The fastest service to return your IP address was " + service); | ||
} else { | ||
console.log("All attempts to retrieve your IP address were exhausted. Is there a problem with your connection?"); | ||
} | ||
}); | ||
Example Output: | ||
Callback Arguments | ||
Your external IP address is 74.125.239.128 | ||
The fastest service to return your IP address was http://whatismyip.akamai.com/ | ||
"ip" - String - Validated IPv4 address (e.g. 74.125.239.128) | ||
"service" - String - The URL of the IP reporting service that produced the returned IP address (e.g. http://whatismyip.akamai.com/) | ||
"err" - Boolean - True when MOIRA was unable to retrieve an IP address | ||
@@ -31,0 +38,0 @@ ## Improving MOIRA ## |
var moira = require('../lib/moira'); | ||
moira.getIP(function(ip, service) { | ||
console.log("Your external IP address is " + ip); | ||
console.log("The fastest service to return your IP address was " + service); | ||
moira.getIP(function(ip, service, err) { | ||
if(!err) { | ||
console.log("Your external IP address is " + ip); | ||
console.log("The fastest service to return your IP address was " + service); | ||
} else { | ||
console.log("All attempts to retrieve your IP address were exhausted. Is there a problem with your connection?"); | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 6 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
0
100
39
0
1
5777
6
59