File Coverage

blib/lib/Net/IP/Identifier/Plugin/Google.pm
Criterion Covered Total %
statement 18 29 62.0
branch n/a
condition 1 3 33.3
subroutine 6 7 85.7
pod 2 3 66.6
total 27 42 64.2


line stmt bran cond sub pod time code
1             #===============================================================================
2             # PODNAME: Net::IP::Identifier::Plugin::Google
3             # ABSTRACT: identify Google (AS15169) owned IP addresses
4             #
5             # AUTHOR: Reid Augustin (REID)
6             # EMAIL: reid@hellosix.com
7             # CREATED: Mon Oct 6 14:01:00 PDT 2014
8             #===============================================================================
9              
10 1     1   19 use 5.008;
  1         3  
  1         32  
11 1     1   4 use strict;
  1         2  
  1         25  
12 1     1   3 use warnings;
  1         2  
  1         31  
13              
14             #_ENTITY_REGEX_ google|postini
15              
16             package Net::IP::Identifier::Plugin::Google;
17              
18 1     1   4 use Role::Tiny::With;
  1         1  
  1         260  
19             with qw( Net::IP::Identifier_Role );
20              
21             our $VERSION = '0.111'; # VERSION
22              
23             sub new {
24 2     2 1 4 my ($class, %opts) = @_;
25              
26 2         4 my $self = {};
27 2   33     13 bless $self, (ref $class || $class);
28              
29             # List of known Google (AS15169) IP blocks as of May 2015
30 2         9 $self->ips(
31             # 17 Network Blocks
32             '8.8.4.0/24',
33             '8.8.8.0/24',
34             '64.18.0.0/20',
35             '64.233.160.0/19',
36             '66.102.0.0/20',
37             '66.249.64.0/19',
38             '72.14.192.0/18',
39             '74.125.0.0/16',
40             '173.194.0.0/16',
41             '207.126.144.0/20',
42             '209.85.128.0/17',
43             '216.239.32.0/19',
44             '2001:4860::/32',
45             '2404:6800::/32',
46             '2607:f8b0::/32',
47             '2800:3f0::/32',
48             '2c0f:fb50::/32',
49             );
50             # NOTE: jwhois 207.126.144.0 - 207.126.159.255 and
51             # 64.18.0.0 - 64.18.15.255 indicate Postini, which is 'Google email
52             # security and archiving services'
53             # NOTE: 2a00:1450:4000::/36 is returned by the refresh method suggested
54             # by Google (see below), but "jwhois 2a00:1450:4000::" indicates it's
55             # unassigned.
56 2         25 return $self;
57             }
58              
59             sub name {
60 9     9 0 870 return 'Google';
61             }
62              
63             sub refresh {
64 0     0 1   my ($self) = @_;
65              
66 0           my $google_DNS = '8.8.8.8'; # public Goodle DNS server _NO_CHECK_
67             # from https://support.google.com/a/answer/60764?hl=en
68 0           my $spf = `nslookup -q=TXT _spf.google.com $google_DNS`;
69             #print "$spf\n";
70 0           my (@blocks) = $spf =~ m/ include:(\S+)/g;
71 0           my @cidrs;
72 0           for my $block (@blocks) {
73 0           my $net_blocks = `nslookup -q=TXT $block $google_DNS`;
74             #print $net_blocks;
75 0           push @cidrs, $net_blocks =~ m/ ip.:(\S+)/g;
76             }
77             # not included in the above algorithm for some reason
78 0           unshift @cidrs, '8.8.8.0/24', '8.8.4.0/24'; # _NO_CHECK_
79 0           delete $self->{ips};
80 0           $self->ips(@cidrs);
81             #print join "\n", '', @cidrs, '';
82             }
83              
84             1;
85              
86             __END__