'use strict';

var request = require( 'request' );

// HTTP requests to a service should return an IP address ONLY in the response body
var services = [
    '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'
];

function getIP( callback ){
    var GetIP = this;

    GetIP.done = false;
    GetIP.isOnItsLastResponse = function() { return GetIP.completedRequests === services.length };
    GetIP.completedRequests = 0;

    services.forEach( function( service ){
        request( service, function( err, response, address ){
            GetIP.completedRequests++;

            if ( address ) address = address.trim();

            if ( GetIP.done === false && thisIsAnIP( address )){
                GetIP.done = true;
                callback( null, address, response.request.uri.href )
            }

            if ( GetIP.done === false && GetIP.isOnItsLastResponse() ){
                callback( new Error( 'All attempts to retrieve your IP address were exhausted' ), null, null )
            }
        });
    })
}

function thisIsAnIP( address ){
    var octet = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.',
        isIP = new RegExp( '^' + octet + octet + octet + octet.slice( 0, -1 ) + '$' );

    if( address ) { return isIP.test( address )} else { return( null )}
}

exports.getIP = getIP;
@@ -490,16 +490,41 @@
  false;%0A
+    GetIP.requests = %5B%5D;%0A
     GetI
@@ -687,24 +687,57 @@
  service )%7B%0A
+        GetIP.requests.push(%0A    
         requ
@@ -794,24 +794,28 @@
             
+  
+  
 GetIP.comple
@@ -830,16 +830,20 @@
 sts++;%0A%0A
+    
         
@@ -892,32 +892,36 @@
 );%0A%0A            
+  
+  
 if ( GetIP.done 
@@ -969,24 +969,28 @@
             
+    
 GetIP.done =
@@ -996,16 +996,151 @@
 = true;%0A
+%0A
+                    GetIP.requests.forEach( function( request )%7B%0A                        request.abort()%0A                    %7D);%0A%0A    
         
@@ -1212,19 +1212,27 @@
         
+ 
-%7D%0A%0A
+   %7D%0A%0A    
         
@@ -1291,24 +1291,28 @@
 sponse() )%7B%0A
+    
             
@@ -1422,16 +1422,20 @@
         
+    
 %7D%0A      
@@ -1436,19 +1436,32 @@
         
+ 
-%7D);
+   %7D)%0A        )
 %0A    %7D)%0A

Abort all other requests when the first IP address is found