File: city.pl

package info (click to toggle)
libgeo-ip-perl 1.51-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,000 kB
  • sloc: perl: 6,844; makefile: 3
file content (38 lines) | stat: -rwxr-xr-x 677 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl

use strict;
use warnings;

use autodie;

use Geo::IP;

my $gi
    = Geo::IP->open( '/usr/local/share/GeoIP/GeoIPCity.dat', GEOIP_STANDARD );

while ( my $host = <DATA> ) {
    chomp $host;
    my $r = $gi->record_by_name($host);
    if ($r) {
        print join(
            "\t",
            $r->country_code, $r->country_name, $r->city,
            $r->region,       $r->region_name,  $r->postal_code,
            $r->latitude,     $r->longitude,    $r->metro_code,
            $r->area_code
        ) . "\n";
    }
    else {
        print "UNDEF\n";
    }
}

__DATA__
12.10.1.4
0.0.0.0
66.108.94.158
yahoo.com
amazon.com
4.2.144.64
24.24.24.24
80.24.24.24