maxmind / GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-php/
Apache License 2.0
2.33k stars 276 forks source link

Log files fill up with AddressNotFoundException on private IPv6 addresses #74

Closed rdev5 closed 8 years ago

rdev5 commented 8 years ago

Affects: https://github.com/Torann/laravel-geoip/issues/55

Error: The address ::1 is not in the database.

I haven't seen any from 127.0.0.1 (IPv4), but GeoIP2 fills up logs very quickly with the above error and stack trace when the error is thrown (discovered by rap2hpoutre/laravel-log-viewer) at https://github.com/maxmind/GeoIP2-php/blob/master/src/Database/Reader.php#L220-L224

Consider adding the following (or a similar implementation) to skip database check if the IP is private:

function is_private_IP($ip) {
    return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE |  FILTER_FLAG_NO_RES_RANGE);
}

Source: https://arjunphp.com/check-if-an-ip-address-is-private-with-php/

oschwald commented 8 years ago

This API throws exceptions on private IPs and other IPs not in the database, as documented. This is the intended behavior. If you do not want this behavior, please consider using MaxMind\Db\Reader directly instead.