Open chrisvdb opened 9 years ago
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.
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.
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