geoip
geoip copied to clipboard
Difference of behaviour between IPv4 and IPv6
GeoIP.lookup
accepts IP addresses as strings or as Erlang IP address (for instance {204, 62, 14, 153}
and it is documented (for instance the example GeoIP.lookup({8,
8, 8, 8})` ). But it is true only for IPv4. IPv6 addresses are only accepted as strings.
iex(2)> GeoIP.lookup({204, 62, 14, 153})
{:ok,
%{
city: "New York City",
country: "US",
hostname: "ada.bortzmeyer.org",
ip: "204.62.14.153",
loc: "40.7143,-74.0060",
org: "AS46636 NatCoWeb Corp.",
postal: "10004",
readme: "https://ipinfo.io/missingauth",
region: "New York",
timezone: "America/New_York"
}}
iex(3)> GeoIP.lookup({8193, 19352, 3520, 65, 534, 16127, 65063, 15679})
{:error,
%GeoIP.Error{
id: nil,
reason: "{\n \"status\": 404,\n \"error\": {\n \"title\": \"Wrong ip\",\n \"message\": \"Please provide a valid IP address\"\n }\n}"
}}
The test suite apparently only tests with IPv4 addresses.
Nice catch! Want to submit a PR for this?