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