Coder Social home page Coder Social logo

geoip-lite / node-geoip Goto Github PK

View Code? Open in Web Editor NEW
2.3K 43.0 353.0 459.06 MB

Native NodeJS implementation of MaxMind's GeoIP API -- works in node 0.6.3 and above, ask me about other versions

Home Page: https://npmjs.org/package/geoip-lite

License: Other

JavaScript 100.00%

node-geoip's Introduction

GeoIP-lite

A native NodeJS API for the GeoLite data from MaxMind.

This product includes GeoLite data created by MaxMind, available from http://maxmind.com/

NOTE You MUST update the data files after installation. The MaxMind license does not allow us to distribute the latest version of the data files with this package. Follow the instructions under update the datafiles for details.

introduction

MaxMind provides a set of data files for IP to Geo mapping along with opensource libraries to parse and lookup these data files. One would typically write a wrapper around their C API to get access to this data in other languages (like JavaScript).

GeoIP-lite instead attempts to be a fully native JavaScript library. A converter script converts the CSV files from MaxMind into an internal binary format (note that this is different from the binary data format provided by MaxMind). The geoip module uses this binary file to lookup IP addresses and return the country, region and city that it maps to.

Both IPv4 and IPv6 addresses are supported, however since the GeoLite IPv6 database does not currently contain any city or region information, city, region and postal code lookups are only supported for IPv4.

philosophy

I was really aiming for a fast JavaScript native implementation for geomapping of IPs. My prime motivator was the fact that it was really hard to get libgeoip built for Mac OSX without using the library from MacPorts.

why geoip-lite

geoip-lite is a fully JavaScript implementation of the MaxMind geoip API. It is not as fully featured as bindings that use libgeoip. By reducing scope, this package is about 40% faster at doing lookups. On average, an IP to Location lookup should take 20 microseconds on a Macbook Pro. IPv4 addresses take about 6 microseconds, while IPv6 addresses take about 30 microseconds.

synopsis

var geoip = require('geoip-lite');

var ip = "207.97.227.239";
var geo = geoip.lookup(ip);

console.log(geo);
{ range: [ 3479298048, 3479300095 ],
  country: 'US',
  region: 'TX',
  eu: '0',
  timezone: 'America/Chicago',
  city: 'San Antonio',
  ll: [ 29.4969, -98.4032 ],
  metro: 641,
  area: 1000 }

installation

1. get the library

$ npm install geoip-lite

2. update the datafiles (optional)

Run cd node_modules/geoip-lite && npm run-script updatedb license_key=YOUR_LICENSE_KEY to update the data files. (Replace YOUR_LICENSE_KEY with your license key obtained from maxmind.com)

You can create a maxmind account here

NOTE that this requires a lot of RAM. It is known to fail on on a Digital Ocean or AWS micro instance. There are no plans to change this. geoip-lite stores all data in RAM in order to be fast.

API

geoip-lite is completely synchronous. There are no callbacks involved. All blocking file IO is done at startup time, so all runtime calls are executed in-memory and are fast. Startup may take up to 200ms while it reads into memory and indexes data files.

Looking up an IP address

If you have an IP address in dotted quad notation, IPv6 colon notation, or a 32 bit unsigned integer (treated as an IPv4 address), pass it to the lookup method. Note that you should remove any [ and ] around an IPv6 address before passing it to this method.

var geo = geoip.lookup(ip);

If the IP address was found, the lookup method returns an object with the following structure:

{
   range: [ <low bound of IP block>, <high bound of IP block> ],
   country: 'XX',                 // 2 letter ISO-3166-1 country code
   region: 'RR',                  // Up to 3 alphanumeric variable length characters as ISO 3166-2 code
                                  // For US states this is the 2 letter state
                                  // For the United Kingdom this could be ENG as a country like “England
                                  // FIPS 10-4 subcountry code
   eu: '0',                       // 1 if the country is a member state of the European Union, 0 otherwise.
   timezone: 'Country/Zone',      // Timezone from IANA Time Zone Database
   city: "City Name",             // This is the full city name
   ll: [<latitude>, <longitude>], // The latitude and longitude of the city
   metro: <metro code>,           // Metro code
   area: <accuracy_radius>        // The approximate accuracy radius (km), around the latitude and longitude
}

The actual values for the range array depend on whether the IP is IPv4 or IPv6 and should be considered internal to geoip-lite. To get a human readable format, pass them to geoip.pretty()

If the IP address was not found, the lookup returns null

Pretty printing an IP address

If you have a 32 bit unsigned integer, or a number returned as part of the range array from the lookup method, the pretty method can be used to turn it into a human readable string.

    console.log("The IP is %s", geoip.pretty(ip));

This method returns a string if the input was in a format that geoip-lite can recognise, else it returns the input itself.

Built-in Updater

This package contains an update script that can pull the files from MaxMind and handle the conversion from CSV. A npm script alias has been setup to make this process easy. Please keep in mind this requires internet and MaxMind rate limits that amount of downloads on their servers.

You will need, at minimum, a free license key obtained from maxmind.com to run the update script.

Package stores checksums of MaxMind data and by default only downloads them if checksums have changed.

Ways to update data

#update data if new data is available
npm run-script updatedb license_key=YOUR_LICENSE_KEY

#force udpate data even if checkums have not changed
npm run-script updatedb-force license_key=YOUR_LICENSE_KEY

You can also run it by doing:

node ./node_modules/geoip-lite/scripts/updatedb.js license_key=YOUR_LICENSE_KEY

Ways to reload data in your app when update finished

If you have a server running geoip-lite, and you want to reload its geo data, after you finished update, without a restart.

Programmatically

You can do it programmatically, calling after scheduled data updates

//Synchronously
geoip.reloadDataSync();

//Asynchronously
geoip.reloadData(function(){
    console.log("Done");
});

Automatic Start and stop watching for data updates

You can enable the data watcher to automatically refresh in-memory geo data when a file changes in the data directory.

geoip.startWatchingDataUpdate();

This tool can be used with npm run-script updatedb to periodically update geo data on a running server.

Environment variables

The following environment variables can be set.

# Override the default node_modules/geoip-lite/data dir
GEOTMPDIR=/some/path

# Override the default node_modules/geoip-lite/tmp dir
GEODATADIR=/some/path

Caveats

This package includes the GeoLite database from MaxMind. This database is not the most accurate database available, however it is the best available for free. You can use the commercial GeoIP database from MaxMind with better accuracy by buying a license from MaxMind, and then using the conversion utility to convert it to a format that geoip-lite understands. You will need to use the .csv files from MaxMind for conversion.

Also note that on occassion, the library may take up to 5 seconds to load into memory. This is largely dependent on how busy your disk is at that time. It can take as little as 200ms on a lightly loaded disk. This is a one time cost though, and you make it up at run time with very fast lookups.

Memory usage

Quick test on memory consumption shows that library uses around 100Mb per process

    var geoip = require('geoip-lite');
    console.log(process.memoryUsage());
    /**
    * Outputs:
    * {
    *     rss: 126365696,
    *     heapTotal: 10305536,
    *     heapUsed: 5168944,
    *     external: 104347120
    * }
    **/

Alternatives

If your use-case requires doing less than 100 queries through the lifetime of your application or if you need really fast latency on start-up, you might want to look into fast-geoip a package with a compatible API that is optimized for serverless environments and provides faster boot times and lower memory consumption at the expense of longer lookup times.

References

Copyright

geoip-lite is Copyright Philip Tellis [email protected] and other contributors, and the latest version of the code is available at https://github.com/bluesmoon/node-geoip

License

There are two licenses for the code and data. See the LICENSE file for details.

node-geoip's People

Contributors

64json avatar adityapatadia avatar ar2rsawseen avatar bevacqua avatar bluesmoon avatar bwp91 avatar chill117 avatar corollari avatar ctalkington avatar dylanpiercey avatar echiu64 avatar ecwyne avatar estliberitas avatar gui avatar hellohungryimdad avatar inversion avatar jamiestivala avatar jimflip avatar jonathanong avatar jordanj77 avatar lneveu avatar lynxysscz avatar orktes avatar ostseb avatar parisholley avatar patelatharva avatar sajal avatar scalder27 avatar surzhynskyi avatar tshemsedinov 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  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  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  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  avatar  avatar

node-geoip's Issues

npm run-script updatedb not work

I try run "npm run-script updatedb" on cmd window but not show anything.
I have figure it out.
@bluesmoon
But I have question why need GeoIPContryCSV if in data directory already have geoip-country.dat and when I download GeoLiteCity.dat.gz what next to do ? with GeoLite files

small memory leak

I tried looping over all IP addresses starting from 0.0.0.0 and doing a lookup for each one and I think I am experiencing a small memory leak.

After about 1 billion lookup, it starts getting really slow on my machine, probably because the memory of the process has increased to 2GB and the GC is trying to free some space.

$ node -v
v0.10.21

Any way I can help finding the leak? A tool I could use to generate a report maybe?

The script :

var geoip = require('geoip-lite');
var a, b, c, d, ip;
for(a=0; a<=255; a++) {
    for(b=0; b<=255; b++) {
        for(c=0; c<=255; c++) {
            for(d=0; d<=255; d++) {
                ip = a+"."+b+"."+c+"."+d;
                geoip.lookup(ip);
            }
        }
        console.log(ip);
    }
}

Encoding problems

var geoip = require('geoip-lite');
var ip = "109.190.22.231";
var geo = geoip.lookup(ip);
console.log(geo);

gives :

{ range: [ 1841174016, 1841174527 ],
country: 'FR',
region: 'A8',
city: 'Montlh�ry',
ll: [ 48.64, 2.2747 ] }

note the city name, it should be 'Montlhéry'

Can't install geoip-lite

Hello.

I get following error message when I try to install it on RHEL6

$ npm install geoip-lite

[email protected] updatedb /home/hayashis/dev/psnow/node_modules/geoip-lite
node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ...
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOSPC, write

npm ERR! [email protected] updatedb: node scripts/updatedb.js
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] updatedb script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/updatedb.js
npm ERR! You can get their info via:
npm ERR! npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.

npm run-script updatedb throws TypeError('value is out of bounds')

node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ... DONE
Processing Data (may take a moment) ...
Still working (197380) ...
Still working (368808) ...
Still working (560022) ...
Still working (761515) ...
Still working (963013) ...
Still working (1168723) ...
Still working (1368510) ...
Still working (1543327) ...
Still working (1721871) ...
buffer.js:784
throw TypeError('value is out of bounds');
^
TypeError: value is out of bounds
at TypeError ()
at checkInt (buffer.js:784:11)
at Buffer.writeInt32BE (buffer.js:924:5)
at processLine (/Users/jaan/Sites/geoiptest/node_modules/geoip-lite/scripts/updatedb.js:337:5)
at /Users/jaan/Sites/geoiptest/node_modules/geoip-lite/node_modules/lazy/lazy.js:99:35
at Lazy. (/Users/jaan/Sites/geoiptest/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:37)
at Lazy.EventEmitter.emit (events.js:98:17)
at Lazy. (/Users/jaan/Sites/geoiptest/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:22)
at Lazy.EventEmitter.emit (events.js:98:17)
at Lazy. (/Users/jaan/Sites/geoiptest/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:22)

super slow install

can we just cache in the module and refresh the data sometimes? I'd definitely prefer to not have to hack around this for deployments but it's way too slow

breaks heroku

the scripts are breaking the build when I upload to heroku

Ofer Velich

Failed to install "npm install geoip-lite" on ubuntu 13.10,
Error stack:
.....
....
Extracting GeoLiteCity-latest.zip ...Killed
npm ERR! [email protected] updatedb: node scripts/updatedb.js
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the [email protected] updatedb script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/updatedb.js
npm ERR! You can get their info via:
npm ERR! npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.11.0-15-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "run-script" "updatedb"
npm ERR! cwd /home/ubuntu/node_modules/geoip-lite
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ubuntu/node_modules/geoip-lite/npm-debug.log
npm ERR! not ok code 0

Reduce RAM footprint by just using country?

First of all - great library, makes a complicated thing so simple.

For our project, all we're looking to do is group customers by country. Is it possible to use this module without having to load in all the other more specific region and metro code data to reduce the memory footprint?

Clearly it'll work with a fork, but curious to see if there's another way.

Encoding problems

var geoip = require('geoip-lite');
var ip = "31.17.105.227";
var geo = geoip.lookup(ip);
console.log(geo);

gives:

{ range: [ 521234688, 521234943 ],
  country: 'DE',
  region: '10',
  city: 'Todenb�ttel',
  ll: [ 54.1333, 9.55 ] }

note the city name, it should be 'Todenbüttel'
Package version: 1.1.0, after running a successful update (npm run-script updatedb).
Also another (small) request: could you update the data files on Git, too? Or are you not allowed to do that?

HTTP Request Failed [403 Forbidden] while installing

I get this error while installing, even though perhaps it was successful. I'm not sure what to make of it

> [email protected] updatedb /Users/tarang/Desktop/testip/node_modules/geoip-lite
> node scripts/updatedb.js

 DONEeving GeoIPCountryCSV.zip ...
 DONEcting GeoIPCountryCSV.zip ...
 DONEssing Data (may take a moment) ...

 DONEeving GeoIPv6.csv ...
 DONEssing Data (may take a moment) ...

ERROR: HTTP Request Failed [403 Forbidden]
[email protected] node_modules/geoip-lite
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])

City data not working

I was having a problem with getting the city data to work, and I noticed there were a few reported issues on here about it. So, I've spent the morning looking into it. It appears the city dat files you download from:
https://github.com/bluesmoon/node-geoip/tree/master/data
Are not correct. They are far too small for one.
geoip-city.dat 21.9kB
geoip-city-names.dat 22kB

So, I went to MaxMind's website (http://dev.maxmind.com/geoip/geolite) and downloaded a new CSV for Cities. When I extracted the ZIP, to my surprise I got 2 files. So, I tried both.

GeoLiteCity-Location.csv is 21.1MB (DIDN'T WORK)
GeoLiteCity-Blocks.csv is 75.5MB (WORKED)

You need to run the command:
node city-converter.js GeoLiteCity-Blocks.csv geoip-city.dat

This produced the files:
geoip-city.dat
geoip-city-names.dat

Put these 2 files in the "Data" folder and it should be working now.
{ range: [ 3479297920, 3479304169 ],
country: 'US',
region: 'TX',
city: 'San Antonio',
ll: [ 29.4889, -98.3987 ] }

Hurray!

Feature Request: Zip/Postal Code

I just noticed zip code isn't parsed out from the City dat. It should be there for requests. I don't know if it's under Postal Code or Zip Code. But should be there for located cities.

Adding citydata returns null for location

When Install geoip-lite, it works fine without city data.

node /node_modules/geoip-lite/test/geo-lookup.js 24.120.170.58

Output:

{ range: [ 410189824, 410648575 ],
country: 'US',
region: '',
city: '',
ll: [ 0, 0 ] }
Startup: 10ms, exec: 4ms

However, when I do:

wget https://github.com/bluesmoon/node-geoip/blob/master/data/geoip-city.dat

and

wget https://github.com/bluesmoon/node-geoip/blob/master/data/geoip-city-names.dat

into /node_modules/geoip-lite/data

Tested with city-data, returns null:

node /node_modules/geoip-lite/test/geo-lookup.js 24.120.170.58

Output:

null
Startup: 8ms, exec: 2ms

npm install error

npm install geoip-lite
npm http GET https://registry.npmjs.org/geoip-lite
npm http 304 https://registry.npmjs.org/geoip-lite
npm http GET https://registry.npmjs.org/async
npm http GET https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/iconv-lite
npm http GET https://registry.npmjs.org/lazy
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/unzip
npm http 304 https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/colors/0.6.0-1
npm http 304 https://registry.npmjs.org/unzip
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/lazy
npm http 304 https://registry.npmjs.org/iconv-lite
npm http 304 https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/fstream
npm http GET https://registry.npmjs.org/pullstream/0.0.4
npm http GET https://registry.npmjs.org/binary
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/fstream
npm http 304 https://registry.npmjs.org/binary
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/pullstream/0.0.4
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/over
npm http GET https://registry.npmjs.org/stream-buffers
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/stream-buffers
npm http 304 https://registry.npmjs.org/over
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/chainsaw
npm http GET https://registry.npmjs.org/buffers
npm http 304 https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/chainsaw
npm http 304 https://registry.npmjs.org/buffers
npm http GET https://registry.npmjs.org/traverse
npm http 304 https://registry.npmjs.org/traverse

[email protected] postinstall /node_modules/geoip-lite
npm run-script updatedb

[email protected] updatedb /node_modules/geoip-lite
node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ...Killed
root@socialwebshop1:/# Killed

npm ERR! [email protected] updatedb: node scripts/updatedb.js
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the [email protected] updatedb script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/updatedb.js
npm ERR! You can get their info via:
npm ERR! npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.8.0-38-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "run-script" "updatedb"
npm ERR! cwd /node_modules/geoip-lite
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /node_modules/geoip-lite/npm-debug.log
npm ERR! not ok code 0

Feature request: DMA codes

We're writing a Node.js application that requires us to selectively block IP addresses by DMA code. I know that we could achieve this by mapping IP address to city using GeoIP-Lite and then mapping city to DMA code using tables from Google AdWords, but synching to those tables regularly could be a pain. Would it difficult to have GeoIP-Lite include DMA code from MaxMind in the location data lookup result? Thanks!

thanks for making this

hey, i'm not sure how else to tell you this other than by filing an issue. just wanted to say thanks for making this--I've never tried compiling the C library that the other libs rely on, but dealing with such things has always been fraught with peril for me. having a fully JS version is enormously useful!

Another geoip-lite installation failure

Hi Everyone,

Yes, another issue but my case is a little different than the other issues.

  • Running vagrant + ubuntu 12.04 + virtualbox
  • the VM has 3gb ram allocated

Most of the time I get this error when provision new machines

> [email protected] postinstall /vagrant/vungle/node_modules/geoip-lite
> npm run-script updatedb


> [email protected] updatedb /vagrant/vungle/node_modules/geoip-lite
> node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ...
Still working (47700) ... DONE

Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ... DONE
Processing Data (may take a moment) ...
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open '/vagrant/vungle/node_modules/geoip-lite/tmp/GeoLiteCity/GeoLiteCity-Blocks.csv'

npm ERR! [email protected] updatedb: `node scripts/updatedb.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] updatedb script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/updatedb.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.8.0-42-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "run-script" "updatedb"
npm ERR! cwd /vagrant/vungle/node_modules/geoip-lite
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /vagrant/vungle/node_modules/geoip-lite/npm-debug.log
npm ERR! not ok code 0
npm ERR! [email protected] postinstall: `npm run-script updatedb`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run-script updatedb
npm ERR! You can get their info via:
npm ERR!     npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.8.0-42-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /vagrant/vungle
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /vagrant/vungle/npm-debug.log
npm ERR! not ok code 0

Sometimes I get this:

Retrieving GeoIPCountryCSV.zip ...ERROR: HTTP Request Failed [403 Forbidden]

Do you think you can help me with this? thanks a lot!

Tony

Feature Request: Reverse Geocode

Thanks for the great module.

I have one more requirement though. I need to find out the city details from the latitude and longitude values. Since the maxmind database already contains tables which contain these values, should that be doable?
I found some node modules which are calling google apis for this, however, I am trying to see if I can achieve this without calling a web service and can do it offline.

GeoIP UpdateDB script fails with 'value is out of bounds' error

I'm suddenly receiving an OOB error:

buffer.js:705
    throw TypeError('value is out of bounds');
          ^
TypeError: value is out of bounds
    at TypeError (<anonymous>)
    at checkInt (buffer.js:705:11)
    at Buffer.writeInt32BE (buffer.js:792:5)
    at processLine (/Users/blimmer/code/Ibotta-Staging/tmp/webapp/dist/node_modules/geoip-lite/scripts/updatedb.js:367:5)
    at /Users/blimmer/code/Ibotta-Staging/tmp/webapp/dist/node_modules/geoip-lite/node_modules/lazy/lazy.js:99:35
    at Lazy.<anonymous> (/Users/blimmer/code/Ibotta-Staging/tmp/webapp/dist/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:37)
    at Lazy.emit (events.js:98:17)
    at Lazy.<anonymous> (/Users/blimmer/code/Ibotta-Staging/tmp/webapp/dist/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:22)
    at Lazy.emit (events.js:98:17)
    at Lazy.<anonymous> (/Users/blimmer/code/Ibotta-Staging/tmp/webapp/dist/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:22)

npm ERR! [email protected] updatedb: `node scripts/updatedb.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] updatedb script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/updatedb.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.

From previously closed issues, it seems like this is caused by a CSV parsing error.

npm release?

Would it be possible to get an updated npm release any time soon?

The new update system, for example, is lovely, but it's not present in the latest tarball on npm

Buffer Overflow

This week the updatedb script started failing, this is the error:

(...)
   Still working (1749315) ...                                                                                             
   Still working (1850667) ...                                                                                             
   buffer.js:784                                                                                                           
       throw TypeError('value is out of bounds');                                                                          
             ^                                                                                                             
   TypeError: value is out of bounds                                                                                       
       at TypeError (<anonymous>)                                                                                          
       at checkInt (buffer.js:784:11)                                                                                      
       at Buffer.writeInt32BE (buffer.js:924:5)                                                                            
       at processLine (/tmp/build_8589d1d9-f0b1-4547-9fa7-48a26db710a7/node_modules/geoip-lite/scripts/updatedb.js:337:5)  
       at /tmp/build_8589d1d9-f0b1-4547-9fa7-48a26db710a7/node_modules/geoip-lite/node_modules/lazy/lazy.js:99:35          
       at Lazy.<anonymous> (/tmp/build_8589d1d9-f0b1-4547-9fa7-48a26db710a7/node_modules/geoip-lite/node_modules/lazy/lazy.js:74:37)     
(...)

Any tips towards solving this?

wrong data when using watch

I've been noticing that at random, geoip look ups were being skewed (ie: my ip was pointing to a completely different place). I believe the issue, is that the npm update-db script actually takes about ~10 minutes for it to complete (GeoLiteCity-latest takes a long time), and when switching between files, not really sure what is going on. I was able to reproduce with this script:

var geoip = require('geoip-lite');

setInterval(function(){
    console.log(geoip.lookup('75.82.117.180'));
}, 2000);

geoip.startWatchingDataUpdate();

I then run the update in the background, and things work great. But as soon as the update completes (i'd say about a minute later), the lookup output changes.

I'm going to try upping the timeout on the watcher to 15 minutes instead of a minute and see if that helps.

npm install fails on Digital Ocean Ubuntu

[email protected] postinstall /home/cloud/node_modules/geoip-lite
npm run-script updatedb

[email protected] updatedb /home/cloud/node_modules/geoip-lite
node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ...
Still working (85333) ... DONE

Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ...Killed

npm ERR! [email protected] updatedb: node scripts/updatedb.js
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the [email protected] updatedb script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/updatedb.js
npm ERR! You can get their info via:
npm ERR! npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.13.0-24-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "run-script" "updatedb"
npm ERR! cwd /home/cloud/node_modules/geoip-lite
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/cloud/node_modules/geoip-lite/npm-debug.log
npm ERR! not ok code 0
npm ERR! [email protected] postinstall: npm run-script updatedb
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run-script updatedb
npm ERR! You can get their info via:
npm ERR! npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.13.0-24-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /home/cloud
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/cloud/npm-debug.log
npm ERR! not ok code 0

Doesn't play nicely with node-webkit

Howdy.

Not sure what's going on here. When I run a script with the following via node-webkit, I get null. When I run with node (via terminal), I get a result.

var geoip = require('geoip-lite');  
var res = geoip.lookup("8.8.8.8");  
console.log(res);

Errors after updating the db

I tried to update the DB from maxmind.
After that I tried to make a lookup for 194.183.97.113
The returning result was:

{ range: [ 3266797872, 3266798591 ],
country: '(u',
region: '�(',
city: '',
ll: [ -176154.1992, 1680.4097 ] }

4 month ago this ip was related to GB and now should be ES.

What I'm doing wrong?
or
What is the right way to update the database?

Installation issue

It depends on the machine, but Ubuntu 14.04 installed via Meteor packages this error occurs:

TypeError: Arguments to path.resolve must be strings
    at Object.exports.resolve (path.js:313:15)
    at mkdirP (/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:15:14)
    at Conf.<anonymous> (/usr/lib/node_modules/npm/node_modules/npmconf/lib/load-prefix.js:29:7)
    at /usr/lib/node_modules/npm/node_modules/npmconf/lib/find-prefix.js:11:7
    at process._tickCallback (node.js:419:13)


/usr/lib/node_modules/npm/lib/npm.js:33
    throw new Error('npm.load() required')
          ^
Error: npm.load() required
    at Object.npm.config.get (/usr/lib/node_modules/npm/lib/npm.js:33:11)
    at exit (/usr/lib/node_modules/npm/lib/utils/error-handler.js:49:27)
    at process.errorHandler (/usr/lib/node_modules/npm/lib/utils/error-handler.js:316:3)
    at process.emit (events.js:95:17)
    at process._fatalException (node.js:272:26)
npm ERR! [email protected] postinstall: `npm run-script updatedb`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the geoip-lite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run-script updatedb
npm ERR! You can get their info via:
npm ERR!     npm owner ls geoip-lite
npm ERR! There is likely additional logging output above.

Post install Segmentation Fault on node 0.10.31

nvm use v0.10.31
Node: 0.10.31
Npm: 1.4.23

> [email protected] postinstall /Users/thomas/work/cine-io/cine/node_modules/geoip-lite
> npm run-script updatedb


> [email protected] updatedb /Users/thomas/work/cine-io/cine/node_modules/geoip-lite
> node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ...Segmentation fault: 11

nvm use v0.10.30
Node: 0.10.30
Npm: 1.4.21

> [email protected] postinstall /Users/thomas/work/cine-io/cine/node_modules/geoip-lite
> npm run-script updatedb


> [email protected] updatedb /Users/thomas/work/cine-io/cine/node_modules/geoip-lite
> node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ... DONE
Processing Data (may take a moment) ...
Still working (152503) ...
Still working (319102) ...
Still working (499383) ...
Still working (726948) ...
Still working (957686) ...
Still working (1187663) ...
Still working (1409492) ...
Still working (1634370) ...
Still working (1858137) ... DONE

Retrieving GeoLiteCityv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Feature Request: Continent Codes

Although only mildly helpful for humans, having continent codes are very useful for bayesian classifiers. For most cases, connections from continents other than their own are suspect.

Running updatedb silently fails while extracting GeoLitCity-latest.zip

A program I wrote to process my site's HTTP logfile uses node-geoip. This is on a Windows machine. The script runs as a command line utility and then ends, it doesn't start a server.

Data returned for IP address (104.193.9.149) is null. When running npm run-script updatedb from the node_modules\geoip-lite folder, this is the output:

> [email protected] updatedb D:\source\github\loghowder\node_modules\geoip-lite
> node scripts/updatedb.js

Retrieving GeoIPCountryCSV.zip ... DONE
Extracting GeoIPCountryCSV.zip ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoIPv6.csv ... DONE
Processing Data (may take a moment) ... DONE

Retrieving GeoLiteCity-latest.zip ... DONE
Extracting GeoLiteCity-latest.zip ...

After this data for the IP address is still not found, even though I think I see it is covered by the MaxMind database.
To prevent a rate-limiting problem to download the files I've waited more then a day to run the update script.

Does someone have a suggestion to solve this? Is there a way to see why the script stops, logging perhaps?

thanks,
rob schlüter

is it blocking?

Hi,
for every request, i got a code like this:

var geo = geoip.lookup(ip);

geo is from : var geoip = require('geoip-lite')

is this a blocking code? my cpu usage goes up to 90-100% sometimes, so I'm looking for the spots that cause the issue, will above code block the request? thanks,

angelo

download data separately

The data files are quite large and it would be nice to not have them download with npm (or maybe even in the git repo). A user would generally only download them once and try to reuse those versions.

Maybe consider having a flag for npm (I think it can do this) to download the files but otherwise let the user specify the data files.

One use case is continuous deployment setups where a fresh clone and thus fresh npm install is done for each instance.

Coordinates?

Are there any plans to start returning a set of get coordinates along with the City/State info?

ISO Country code to full country name

Currently the only country output available via node-geoip is the short ISO code. Is it possible to add the full country name to the output or via some option var?

no working

Hey,

Every time i try to require the library, i get a screen full of weird charaters (i guess the binary data converted to string) and the lookup never run

Is this library up to date anymore?

Outside ipv4 range

The example code under synopsis, returns null for being outside IPv4 range. This is on node v0.6.14.

Also, it would be helpful to return error messages or responses, instead of just null.

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.