line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::DNS; |
2
|
2
|
|
|
2
|
|
27197
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
7
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
114
|
|
5
|
2
|
|
|
2
|
|
784
|
use URI::Escape qw/uri_escape/; |
|
2
|
|
|
|
|
1961
|
|
|
2
|
|
|
|
|
89
|
|
6
|
2
|
|
|
2
|
|
1300
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
72411
|
|
|
2
|
|
|
|
|
70
|
|
7
|
2
|
|
|
2
|
|
1317
|
use JSON::PP qw/decode_json/; |
|
2
|
|
|
|
|
21379
|
|
|
2
|
|
|
|
|
149
|
|
8
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
9
|
2
|
|
|
|
|
13
|
rw => [qw/ |
10
|
|
|
|
|
|
|
cd |
11
|
|
|
|
|
|
|
type |
12
|
|
|
|
|
|
|
endpoint |
13
|
|
|
|
|
|
|
ua |
14
|
|
|
|
|
|
|
/], |
15
|
2
|
|
|
2
|
|
945
|
); |
|
2
|
|
|
|
|
1530
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
21
|
0
|
|
|
|
|
|
my %args = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
bless { |
24
|
|
|
|
|
|
|
cd => ($args{cd} || $args{dnssec}) ? 1 : 0, |
25
|
|
|
|
|
|
|
type => $args{type} || '', |
26
|
|
|
|
|
|
|
endpoint => $args{endpoint} || 'https://dns.google.com/resolve', |
27
|
0
|
0
|
0
|
|
|
|
ua => $args{ua} || HTTP::Tiny->new, |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub resolve { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $domain, $raw) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
croak "require domain" unless $domain; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my %query = (name => $domain); |
37
|
0
|
0
|
|
|
|
|
if ($self->cd) { |
38
|
0
|
|
|
|
|
|
$query{cd} = $self->cd; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
0
|
|
|
|
|
if ($self->type) { |
41
|
0
|
|
|
|
|
|
$query{type} = $self->type; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
my $query_string = join('&', map { uri_escape($_).'='.uri_escape($query{$_}) } keys %query); |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $res = $self->ua->get($self->endpoint.'?'. $query_string); |
46
|
0
|
0
|
|
|
|
|
croak "wrong response:$res->{status} $res->{reason}" unless $res->{success}; |
47
|
0
|
|
|
|
|
|
my $json = $res->{content}; |
48
|
0
|
0
|
|
|
|
|
return $json if $raw; |
49
|
0
|
|
|
|
|
|
return decode_json($json); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub data { |
53
|
0
|
|
|
0
|
1
|
|
my ($self, $domain, $delimi) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
unless (defined $delimi) { |
56
|
0
|
|
|
|
|
|
$delimi = "\n"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $hash = $self->resolve($domain); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return join($delimi, map { $_->{data} } @{$hash->{Answer}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |