gpslab / geoip2

A Symfony Bundle for the Maxmind GeoIP2 API
https://www.maxmind.com/
MIT License
54 stars 12 forks source link

Usage of ASN database #8

Closed henri9813 closed 4 years ago

henri9813 commented 5 years ago

Hello,

How can i use ASN database with your bundle ?

Best regards

peter-gribanov commented 5 years ago

This bundle only registers services of maxmind/GeoIP2-php. If maxmind/GeoIP2-php supports ASN (i think it does), then you can use it with this bundle.

You can try with this config:

gpslab_geoip:
    cache: '%kernel.cache_dir%/GeoLite2-ASN.mmdb'
    url: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz'
henri9813 commented 5 years ago

Yes it support it,

So, i can't read multiple mmdb files ?

peter-gribanov commented 5 years ago

So, i can't read multiple mmdb files ?

Yes. Currently, the bundle does not allow working simultaneously with several database files.

You can independently register a separate service for ASN database.

services:
    geoip2.reader.asn:
        class: GeoIp2\Database\Reader
        arguments: [ '%kernel.cache_dir%/GeoLite2-ASN.mmdb', '%geoip2.locales%' ]
        public: true

And you can update it with command:

bin/console geoip2:update "https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz" "path/to/cache/dir/GeoLite2-ASN.mmdb"
henri9813 commented 5 years ago

Okay,

Thanks for your reply ! :+1: :1st_place_medal:

peter-gribanov commented 4 years ago

Now you can use multiple GeoIP databases in one application. Need update configuration file.

gpslab_geoip:
    databases:
        default:
            license: 'XXXXXXXXXXXXXXXX'
            edition: 'GeoLite2-City'
        asn:
            license: 'XXXXXXXXXXXXXXXX'
            edition: 'GeoLite2-ASN'

Using in application:

// get a GeoIP2 reader for City database
$default_reader = $this->get('geoip2.database.default_reader');
// or
//$default_reader = $this->get(Reader::class);
// or
//$default_reader = $this->get('geoip2.reader');

// get a GeoIP2 reader for ASN database
$asn_reader = $this->get('geoip2.database.asn_reader');

See README file for more detals.