http://qs321.pair.com?node_id=11118413


in reply to Help with Geo::IP output

As my fellow monk already mentioned, MaxMind can be done using App::geoip:

$ geoip -w 103.2.106.33 GeoIP data for 103.2.106.33 - (hostname not found): CIDR : 103.2.104.0/22 IP range : 103.2.104.0 - 103.2.107.255 Provider : Singapore Telecommunications Limited City : Country : SG Singapore Continent : Asia Timezone : Asia/Singapore Location : 1.3667 / 103.8000 (50) 1°22'00.12" / 103°48'0 +0.00" https://www.openstreetmap.org/#map=13/1.3667/103.8000 https://www.google.com/maps/place/@1.3667,103.8000,13z Location : 52.2892 / 5.2603 52°17'21.13" / 5°15'3 +6.92" Distance : ± 10467.30km Whois information: Name : Singapore Telecommunications Limited ID : CO122-AP Phone : +65 83180832 EMail : opsinfosvc@singtel.com Abuse : opsinfosvc@singtel.com Address : 7 Bedok South Road NCS Bedok EU member : No Satellite : No Anon Proxy: No
$ geoip --json-pretty 103.2.106.33 [ { "rep_continent" : "", "map_urls" : [ "https://www.openstreetmap.org/#map=13/1.3667/103.8000", "https://www.google.com/maps/place/@1.3667,103.8000,13z" ], "longitude" : "103.8000", "local_longitude" : "---", "accuracy" : "50", "longitude_dms" : "103°48'00.00\"", "ip_to_n" : 1728211967, "postal_code" : "", "distance_unit" : "km", "city_tz" : "Asia/Singapore", "local_latidue_dms" : "---", "ip" : "103.2.106.33", "reg_continent" : "Asia", "provider" : "Singapore Telecommunications Limited", "local_latitude" : "---", "reg_ctry_eu" : 0, "hostname" : "(hostname not found)", "latitude_dms" : "1°22'00.12\"", "city" : "", "local_longitude_dms" : "---", "distance" : 10467.2979838297197, "reg_ctry_iso" : "SG", "rep_ctry_name" : "", "cidr" : "103.2.104.0/22", "ip_to" : "103.2.107.255", "city_metro_code" : "", "ip_from_n" : 1728210944, "rep_ctry_iso" : "", "city_name" : "", "reg_ctry_name" : "Singapore", "id" : 1880251, "ip_from" : "103.2.104.0", "latitude" : "1.3667", "ip_n" : 1728211489, "satellite" : 0, "anon_proxy" : 0 } ]

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Help with Geo::IP output
by Anonymous Monk on Jun 24, 2020 at 12:05 UTC

    Thanks you for much for the example.

    How do you call it from your script after you have installed the module?

      Currently you don't. It is a module in the App:: namespace. If you want to use the infrastructure generated by geoip steal the code from geoip or use it's json output in a pipe:

      use JSON::MaybeXS; open my $gh, "-|", "geoip", "--json", $url_or_hostname or die; my $data = decode_json (do { local $/; <$gh> }); say $data->[0]{provider}; # [0] as it returns a list of matches

      Enjoy, Have FUN! H.Merijn

        As with the other post today, in a piped open, close needs to be checked for errors as well. Or, let me just plug my relatively new module IPC::Run3::Shell::CLIWrapper ;-)

        use JSON::PP qw/decode_json/; use IPC::Run3::Shell::CLIWrapper; my $geoip = IPC::Run3::Shell::CLIWrapper->new( { fail_on_stderr=>1, stdout_filter => sub {$_=decode_json($_)} }, qw/ geoip --json --DB=dbi:SQLite:dbname=geoipdb / ); my $data = $geoip->('209.197.123.153');
Re^2: Help with Geo::IP output
by Anonymous Monk on Jun 24, 2020 at 13:00 UTC

    I got the following error:

    FATAL: no pg_hba.conf entry for host "[local]", user "xxx", database +"geoip", SSL off Cannot continue without a working database
    How do I set up the config file?

      Use a supported database, see dsn.