Git Product home page Git Product logo

node-geoip-native's People

Contributors

benlowry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-geoip-native's Issues

npm install fails with 404

npm install geoip-native

npm http GET https://registry.npmjs.org/geoip-native
npm http 304 https://registry.npmjs.org/geoip-native
npm http GET https://registry.npmjs.org/geoip-native/-/geoip-native-0.0.8.tgz
npm http 404 https://registry.npmjs.org/geoip-native/-/geoip-native-0.0.8.tgz
npm ERR! fetch failed https://registry.npmjs.org/geoip-native/-/geoip-native-0.0.8.tgz
npm ERR! Error: 404 Not Found
npm ERR! at null. (/usr/local/Cellar/node/0.8.16/lib/node_modules/npm/lib/utils/fetch.js:47:16)
npm ERR! at EventEmitter.emit (events.js:126:20)
npm ERR! at WriteStream.flush (fs.js:1529:12)
npm ERR! at fs.close (/usr/local/Cellar/node/0.8.16/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:90:5)
npm ERR! at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

Invalid lookup?

I noticed a bug in my app for IP "207.47.0.226". It was not showing up as US, even though the CSV says it should have.

I rewrote the binary search and verified it works as expected, so I think there is a bug lurking in the binary search lookup code.

console.log(geoip.lookup('207.47.0.226'))
// { ipstart: 3277684736, code: 'RU', name: 'Russian Federation' }

Proper CSV Line it should have matched:

"207.46.90.0","207.47.127.255","3475921408","3475996671","US","United States"

Faster but less accurate?

Unless I'm missing something I think I should be able to look up an IP taken from the CSV and get the same country back. For example these lines are pulled from the middle of the CSV:

    data = [ { start:"125.255.0.0",end:"125.255.255.255",lower:"2113863680",upper:"2113929215",code:"AU",country:"Australia" },
        { start:"126.0.0.0",end:"126.255.255.255",lower:"2113929216",upper:"2130706431",code:"JP",country:"Japan" },
        { start:"128.0.0.0",end:"128.0.7.255",lower:"2147483648",upper:"2147485695",code:"RO",country:"Romania" },
        { start:"128.0.8.0",end:"128.0.15.255",lower:"2147485696",upper:"2147487743",code:"DK",country:"Denmark" },
        { start:"128.0.16.0",end:"128.0.23.255",lower:"2147487744",upper:"2147489791",code:"NO",country:"Norway" },
        { start:"128.0.24.0",end:"128.0.31.255",lower:"2147489792",upper:"2147491839",code:"RU",country:"Russian Federation" } ]

If I run them through a test script I get:

% node test-2.js
starting test: geoip-native
Looking up IP 125.255.0.0 (AU)
    native: FAIL: CN != AU - {"ipstart":2113830912,"code":"CN","name":"China"}
Looking up IP 126.0.0.0 (JP)
    native: FAIL: AU != JP - {"ipstart":2113863680,"code":"AU","name":"Australia"}
Looking up IP 128.0.0.0 (RO)
    native: FAIL: JP != RO - {"ipstart":2113929216,"code":"JP","name":"Japan"}
Looking up IP 128.0.8.0 (DK)
    native: FAIL: EU != DK - {"ipstart":2147483648,"code":"EU","name":"Europe"}
Looking up IP 128.0.16.0 (NO)
    native: FAIL: EU != NO - {"ipstart":2147483648,"code":"EU","name":"Europe"}
Looking up IP 128.0.24.0 (RU)
    native: FAIL: EU != RU - {"ipstart":2147483648,"code":"EU","name":"Europe"}
native: 6 failed; 0 correct
starting test: geoip-lite
Looking up IP 125.255.0.0 (AU)
    lite: CORRECT: AU == AU - {"range":[2113863680,2113863933],"country":"AU","region":"02","city":"Newcastle","ll":[-32.9278,151.7845]}
Looking up IP 126.0.0.0 (JP)
    lite: CORRECT: JP == JP - {"range":[2113929216,2114191359],"country":"JP","region":"","city":"","ll":[36,138]}
Looking up IP 128.0.0.0 (RO)
    lite: CORRECT: RO == RO - {"range":[2147483648,2147485695],"country":"RO","region":"","city":"","ll":[46,25]}
Looking up IP 128.0.8.0 (DK)
    lite: CORRECT: DK == DK - {"range":[2147485696,2147487743],"country":"DK","region":"","city":"","ll":[56,10]}
Looking up IP 128.0.16.0 (NO)
    lite: CORRECT: NO == NO - {"range":[2147487744,2147489791],"country":"NO","region":"","city":"","ll":[62,10]}
Looking up IP 128.0.24.0 (RU)
    lite: CORRECT: RU == RU - {"range":[2147489792,2147491839],"country":"RU","region":"","city":"","ll":[60,100]}
lite: 0 failed; 6 correct

Running the entire CSV through the test I get:

native: 73876 failed; 6577 correct
lite: 7195 failed; 70384 correct

I attribute the failures in GeoIP's "lite" implementation to some administrative accuracy differences in the datasets uses (many places show up as "EU" rather than the actual country in the binary datasets for some reason).

I'm still zeroing in on the actual bug but at least this test case makes it easy to spot:

var geoip = require("./geoip.js");
//var geoip = require("geoip-lite");


function readCountries()
{
    var fs = require("fs");
    var sys = require("sys");
    // var stream = fs.createReadStream(__dirname + "/GeoIPCountryWhois.csv");
    var buffer = fs.readFileSync(__dirname + "/GeoIPCountryWhois-new.csv", { encoding: "UTF8"} );
    var countries = [];

    buffer = buffer.replace(/"/g, "");

    var entries = buffer.split("\n");

    for(var i=0; i<entries.length; i++) {
        var entry = entries[i].split(",");
        countries.push({start: entry[0], ipstart: parseInt(entry[2]), code: entry[4], name: entry[5]});
    }

    countries.sort(function(a, b) {
        return a.ipstart - b.ipstart;
    });

    numcountries = countries.length;

    return countries;
}
var test1 = true;

function test() {

    var total = 0;
    var numtests = 20;
    var numiterations = 1000000;

    console.log("starting test: " + (test1 ? "geoip-native" : "geoip-lite"));

    data = [ { start:"125.255.0.0",end:"125.255.255.255",lower:"2113863680",upper:"2113929215",code:"AU",country:"Australia" },
        { start:"126.0.0.0",end:"126.255.255.255",lower:"2113929216",upper:"2130706431",code:"JP",country:"Japan" },
        { start:"128.0.0.0",end:"128.0.7.255",lower:"2147483648",upper:"2147485695",code:"RO",country:"Romania" },
        { start:"128.0.8.0",end:"128.0.15.255",lower:"2147485696",upper:"2147487743",code:"DK",country:"Denmark" },
        { start:"128.0.16.0",end:"128.0.23.255",lower:"2147487744",upper:"2147489791",code:"NO",country:"Norway" },
        { start:"128.0.24.0",end:"128.0.31.255",lower:"2147489792",upper:"2147491839",code:"RU",country:"Russian Federation" } ]

    failed = 0;
    correct = 0;
    testname = (test1 ? "native" : "lite");
    countries = data; // readCountries();

    for (i = 0; i < countries.length; i++)
    {
        console.log("Looking up IP " + countries[i].start + " ("+ countries[i].code + ")");
        lookedup = geoip.lookup(countries[i].start);
        if (lookedup)
        {
            lookedup_code = (test1 ? lookedup.code : lookedup.country)
            if (lookedup_code != countries[i].code)
            {
                ++failed;
                console.log("\t" + testname + ": FAIL: " + lookedup_code + " != " + countries[i].code + " - " + JSON.stringify(lookedup))
            }
            else
            {
                ++correct;
                console.log("\t" + testname + ": CORRECT: " + lookedup_code + " == " + countries[i].code + " - " + JSON.stringify(lookedup))
            }
        }
    }

    console.log(testname + ": " + failed + " failed; " + correct + " correct");

    if(!test1) {
        return;
    }

    geoip = require("geoip-lite");
    test1 = false;
    test();
}

setTimeout(test, 1000);

Or has looking at this for a couple of hours blinded me to something obvious?

publish latest version

Hi and thank you for your great work! <3

Here is the great news: geoip-native still runs on Node v6.10.3

The currently published version still makes use of the deprecated sys -- can you publish an updated version?

Thanks and all the best from Germany!

Faulty example

var geoip = require("geoip-native");
var ip = "123.123.123.123";
geoip.lookup(ip);
console.log("country: " + ip.name + " / " + ip.code);

Should be more like:

var geoip = require("geoip-native");
var ip = "123.123.123.123";
var result = geoip.lookup(ip);
console.log("country: " + result.name + " / " + result.code);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.