Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Geoip-lite returns null for IPv6 representation of IPv4 addresses #84

Open
chrisvdb opened this issue Apr 23, 2015 · 2 comments
Open

Geoip-lite returns null for IPv6 representation of IPv4 addresses #84

chrisvdb opened this issue Apr 23, 2015 · 2 comments

Comments

@chrisvdb
Copy link

Using my current IP address:

var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
console.log(ip);
var geo = geoip.lookup(ip);
console.log(geo);

yields

::ffff:123.202.30.78
null

My geoip-lite data directory contains:

-rw-r--r-- 1 root root 40M Feb 11 15:20 geoip-city-names.dat
-rw-r--r-- 1 root root 23M Feb 11 15:20 geoip-city.dat
-rw-r--r-- 1 root root 1.3M Feb 11 15:20 geoip-city6.dat
-rw-r--r-- 1 root root 1001K Feb 11 15:20 geoip-country.dat
-rw-r--r-- 1 root root 726K Feb 11 15:20 geoip-country6.dat

(root because it's in a docker container)

Looking up the IPv4 version (123.202.30.78) works as expected. Looking
up ::ffff:123.202.30.78 on https://www.maxmind.com/en/geoip-demo works
as expected too.

A workaround is:

ip = ip.split(:).slice(-1)[0]; // works both on IPv4 and IPv6 representations of IPv4 addresses

@Rytiss
Copy link

Rytiss commented Jul 17, 2015

Confirming - I have the same issue. My workaround is ip.substr(7) since I always know that I'll get IPv4s, so I just drop IPv6 prefix.

@ollyde
Copy link

ollyde commented Nov 11, 2022

I did a test myself.

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

I get

{
  range: [ 2076843520, 2076843775 ],
  country: 'HK',
  region: 'HCW',
  eu: '0',
  timezone: 'Asia/Hong_Kong',
  city: 'Central',
  ll: [ 22.2908, 114.1501 ],
  metro: 0,
  area: 5
}

I'm using the premium database though.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants