BGPmon-CPM-Prefix-Finder-1

 view release on metacpan or  search on metacpan

lib/BGPmon/CPM/Prefix/Finder.pm  view on Meta::CPAN

    }
  ## get the data about the organization out of the original structure
  }else{
    $org_info{'source'} = 'ARIN';
    $org_info{'netname'} = $res_struct->{'net'}->{'name'}->{'$'};
    $org_info{'orgname'} = $res_struct->{'net'}->{'orgRef'}->{'@name'};
    $org_info{'orghandle'} = $res_struct->{'net'}->{'orgRef'}->{'@handle'};
    $org_info{'inetnum'} = $res_struct->{'net'}->{'startAddress'}->{'$'} .
                           "-" . $res_struct->{'net'}->{'endAddress'}->{'$'} ;

  }
  return %org_info;
}

=head2 inetnum2prefixes

This subroutine expands an inetnum into a list of prefixes that cover the space.

Input: inetnum
Output: array of prefixes

=cut
sub inetnum2prefixes{

  my $inetnum = shift;
  my ($start,$end) = split /-/,$inetnum;
  my @prefixes;
  $start =~ s/\s*//g;
  $end =~ s/\s*//g;

  my $version = 0;
  if(ip_is_ipv4($start) && ip_is_ipv4($end)){
    $version = 4;
  }elsif(ip_is_ipv6($start) && ip_is_ipv6($end)){
    $version = 6;
  }else{
    return @prefixes;
  }
  my $sbin = ip_iptobin($start,$version);
  my $ebin = ip_iptobin($end,$version);
  if(!defined($sbin) || !defined($ebin)){
    return @prefixes;
  }
  return ip_range_to_prefix($sbin,$ebin,$version);
}

=head2 netname2prefixes

This subroutine expands a netname to a list of prefixes

Input: source and netname
Output: array of prefixes

=cut
sub netname2prefixes{
  my $source = shift;
  my $netname = shift;

  my $ua = LWP::UserAgent->new;
  my $res = $ua->get("http://apps.db.ripe.net/whois/grs-search?" .
                     "&type-filter=inetnum&type-filter=inet6num" .
                     "&source=$source-grs&query-string=$netname" .
                     "&flags=Cr",'Accept'=>'application/json');
  my $res_struct = decode_json($res->content);
  print Dumper($res_struct);
}

=head2 orghandle2nets

Input: orghandle
Output: array of nets

=cut
sub orghandle2nets{
  my $orghandle = shift; 
  my @nets;

  ## this only works within ARIN
  my $query = "http://whois.arin.net/rest/org/$orghandle/nets";
  my $ua = LWP::UserAgent->new;
  my $res = $ua->get($query,'Accept'=>'application/json');
  my $res_struct = decode_json($res->content);
  if($res_struct->{'nets'}->{'netRef'} !~ /ARRAY/){
    return @nets;
  }
  foreach my $netref (@{$res_struct->{'nets'}->{'netRef'}}){
    push @nets,$netref->{'@startAddress'} . "-" . $netref->{'@endAddress'};
  }
  return @nets;
}

=head2 expandDomainToIPs

Expands a domain name to a list of IPs.
The expansion can be controlled throug the following options.
 follow_NS => include name servers in the expansion
 follow_CNAME => include domain names linked through CNAMES
 follow_MX => include mail exchange servers
 follow_SOA => include the primary authoritative nameserver
 only_A => only include IPv4
 only_AAAA => only include IPv6
By default the code follows all of the above record types and includes
both IPv4 and IPv6 IP addresses.

Input: a domain name
Output: a hash of IP addresses
        each IP address has 2 hashes associated with it 
        1. 'domains' and 2. 'search_strings'

=cut
sub expandDomainToIPs{

  my %processQ;
  my %processedSet;
  my %ips;

  # get the arguments
  my $domain_ref = shift;
  my @domains = @$domain_ref;
  my %options = @_;
  my $follow_MX = defined($options{'follow_MX'}) ? $options{'follow_MX'} : 1;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.914 second using v1.00-cache-2.02-grep-82fe00e-cpan-9f2165ba459b )