From: Vsevolod Stakhov Date: Tue, 27 Feb 2018 12:25:25 +0000 (+0000) Subject: [Minor] Improve asn.pl helper script X-Git-Tag: 1.7.0~111 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc08cc1e47b0b4a7cbc83f356861517d125c12a8;p=rspamd.git [Minor] Improve asn.pl helper script --- diff --git a/utils/asn.pl b/utils/asn.pl index 5959b5c93..be56c0962 100644 --- a/utils/asn.pl +++ b/utils/asn.pl @@ -32,7 +32,7 @@ my $download_target = "./"; my $help = 0; my $man = 0; my $v4 = 1; -my $v6 = 0; +my $v6 = 1; my $parse = 1; my $v4_zone = "asn.rspamd.com"; my $v6_zone = "asn6.rspamd.com"; @@ -43,7 +43,7 @@ GetOptions( "download-asn" => \$download_asn, "download-bgp" => \$download_bgp, "4!" => \$v4, - "6" => \$v6, + "6!" => \$v6, "parse!" => \$parse, "target=s" => \$download_target, "zone-v4=s" => \$v4_zone, @@ -116,6 +116,10 @@ foreach my $u ( @{ $config{'bgp_sources'} } ) { my $net = $dd->{'prefix'} . '/' . $dd->{'bits'}; if ( $entry && $entry->{'AS_PATH'} ) { my $as = $entry->{'AS_PATH'}->[-1]; + if (ref($as) eq "ARRAY") { + $as = @{$as}[0]; + } + if ( !$networks->{$as} ) { if ( $dd->{'subtype'} == 2 ) { $networks->{$as} = { nets_v4 => [$net], nets_v6 => [] }; @@ -153,9 +157,15 @@ foreach my $u ( @{ $config{'asn_sources'} } ) { my $as_end = $as_start + int( $elts[4] ); for ( my $as = $as_start ; $as < $as_end ; $as++ ) { - if ( $networks->{"$as"} ) { - $networks->{"$as"}->{'country'} = $elts[1]; - $networks->{"$as"}->{'rir'} = $elts[0]; + my $real_as = $as; + + if (ref($as) eq "ARRAY") { + $real_as = @{$as}[0]; + } + + if ( $networks->{"$real_as"} ) { + $networks->{"$real_as"}->{'country'} = $elts[1]; + $networks->{"$real_as"}->{'rir'} = $elts[0]; } } } @@ -201,8 +211,12 @@ asn.pl [options] Options: --download-asn Download ASN data from RIR - --download-bgp Download GeoIP data from Maxmind + --download-bgp Download GeoIP data from Maxmind --target Where to download files (default: current dir) + --zone-v4 IPv4 zone (default: asn.rspamd.com) + --zone-v6 IPv6 zone (default: asn6.rspamd.com) + --file-v4 IPv4 zone file (default: ./asn.zone) + --file-v6 IPv6 zone (default: ./asn6.zone) --help Brief help message --man Full documentation