GeoIP2 指定IP查询

GeoIP2 specify IP to query

如何使用 MaxMind GeoIP JavaScript API 指定要查询的 IP 地址?它应该非常简单,但我在他们的文档中找不到它。

这是我使用的功能,但是它会自动查询我自己的IP地址。我想指定一个不同的IP地址来查询。

geoip2.country(onSuccess, onError);

你有 wfUtils 对象上的 IP2Country 方法吗?

在PHP我这样做。

global $geo_location;
$ip = wfUtils::getIP();
$geo_location = wfUtils::IP2Country($ip);
if ($geo_location === 'US') {...}

MaxMind GeoIP2 JavaScript API 仅returns 当前设备的信息,使用设备连接到 MaxMind 服务器的 IP 地址。无法将任意 IP 地址传递给它。

我不知道你是在做前端还是后端 JS,但在后端你可以使用一些东西 geoip2ws for web service access or maxmind 来查询本地 GeoIP2/GeoLite2 数据库。