| 1 | package GlbDNS::Resolver::ShowLocation; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use List::Util qw(shuffle); | ||
| 5 | use Net::DNS::RR::TXT; | ||
| 6 | use Geo::IP; | ||
| 7 | my $gi = Geo::IP->open_type( GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD); | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my $class = shift; | ||
| 11 | return bless {}, $class | ||
| 12 | } | ||
| 13 | |||
| 14 | sub request { | ||
| 15 | my ($self, $glbdns, $qname, $qclass, $qtype, $peerhost, $query) = @_; | ||
| 16 | $qname = lc($qname); | ||
| 17 | if ($qname =~/glbdns-show-calling-location/) { | ||
| 18 | my @ans; | ||
| 19 | my $record = $gi->record_by_addr($peerhost); | ||
| 20 | return ("NOERROR", [ | ||
| 21 | Net::DNS::RR::TXT->new({ | ||
| 22 | name => "$qname", | ||
| 23 | ttl => 1, | ||
| 24 | class => "IN", | ||
| 25 | type => "TXT", | ||
| 26 | txtdata => "LAT: " . $record->latitude . " LON: " . $record->longitude . " CITY: " . $record->city}) | ||
| 27 | ], [], [],{ aa => 1}); | ||
| 28 | } | ||
| 29 | return (); | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; |