New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

moira

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moira - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

28

lib/moira.js
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

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