/
makani
/
lg
Обзор
Документация
Войти
/
makani
/
lg
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
makeaslist.pl
222 строки
4 KB
Cougar
! updates from Kaloyan Tenchov:
20 дек 2006, 09:45
20 дек 2006, 09:45
61a5f48
Код
Авторство
О чём код?
#!/usr/bin/perl &make_arin; &make_nic("RIPE", "ftp://ftp.ripe.net/ripe/dbase/split/ripe.db.aut-num.gz", "as-ripe.txt"); &make_nic("APNIC", "ftp://ftp.apnic.net/pub/whois-data/APNIC/split/apnic.db.aut-num.gz", "as-apnic.txt"); &make_nic("JPNIC", "ftp://ftp.apnic.net/pub/whois-data/JPNIC/split/jpnic.db.aut-num.gz", "as-jpnic.txt"); &make_lacnic; &make_afrinic; sub make_arin() { open (F1, "wget -q -O - ftp://ftp.arin.net/info/asn.txt |"); open (F2, "> as-arin.txt"); print F2 <<EOT; # # This file is generated automatically from # ftp://ftp.arin.net/netinfo/asn.txt # # Do not edit this file # EOT while (<F1>) { chop; next if (/ APNIC-AS-\d+-BLOCK /); next if (/ APNIC-AS-BLOCK /); next if (/ APNIC-AS-X-BLOCK /); next if (/ RIPE-\d+ /); next if (/ RIPE-ASN?BLOCK-?\d+ /); next if (/ ASNBLK-RIPE /); next if (/ ASNBLK-RIPE-NCC /); next if (/ ASN-BLKRIPE\d+ /); next if (/ APNIC-\d+ /); next if (/ LACNIC-\d+ /); next if (/ AFRINIC-ASNBLOCK-\d+ /); if (/^\s*([\d\-]+)\s+(\S+)\s/) { my $autnum = $1; my $descr = $2; if ($autnum =~ /^(\d+)-(\d+)$/) { for (my $i = $1; $i <= $2; $i++) { printf(F2 "%5d\tARIN:%s\n", $i, $descr); } } else { printf(F2 "%5d\tARIN:%s\n", $autnum, $descr); } } else { next; } } close F2; close F1; } sub make_nic() { my ($nicprefix, $url, $filename) = @_; open (F1, "wget -q -O - $url | gunzip |"); my $autnum = ""; my $descr = ""; my $nic = $nicprefix; my @asnum; while (<F1>) { chop; if (/^aut-num:\s+[Aa][Ss](\d+)$/) { $autnum = $1; next; } elsif (/^as-name:\s+(.*)$/) { next if ($1 eq "UNSPECIFIED"); $descr = $1 if ($descr eq ""); next; } elsif (/^descr:\s+(.*\w.*)$/) { next if ($autnum eq ""); $descr = $1 if ($descr eq ""); next; } elsif (/^mnt-by:\s+MNT-KRNIC-AP$/) { # Mark KRNIC records in the APNIC database $nic = 'KRNIC'; next; } elsif ($_ eq '') { # Write information to the $asnum array } else { next; } if ($autnum ne "") { $asnum[$autnum] = "$nic:$descr"; $autnum = ""; $name = ""; $descr = ""; $nic = $nicprefix; } else { print STDERR "missing aut-num for as-name [$1] in line $.\n"; } } close F1; open (F2, "> $filename"); print F2 <<EOT; # # This file is generated automatically from # $url # # Do not edit this file # EOT for (my $i = 1; $i < 65536; $i++) { next unless ($asnum[$i] ne ""); # Skip JPNIC allocations in APNIC database next if ($asnum[$i] =~ /^APNIC:JPNIC-/); # Remove comments in RIPE and APNIC as-name fields $asnum[$i] =~ s/#.+$//; printf(F2 "%5d\t%s\n", $i, $asnum[$i]); } close F2; } sub get_lacnic_as_desc() { my $asn = $_[0]; my $country = $_[1]; my $asowner = '?'; open (F35, "wget -q -O - \"http://lacnic.net/cgi-bin/lacnic/whois?lg=EN&query=AS$asn\" |"); while (<F35>) { chop; if (/^owner:\s+(.+)$/) { $asowner = $1; last; } } close F35; return "$asowner, $country"; } sub make_lacnic() { open (F1, "wget -q -O - ftp://whois.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest |"); open (F2, "> as-lacnic.txt"); print F2 <<EOT; # # This file is generated automatically from # ftp://whois.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest # # Do not edit this file # EOT while (<F1>) { chop; if (/^lacnic\|([A-Z][A-Z])\|asn\|(\d+)\|/) { printf(F2 "%5d\tLACNIC:%s\n", $2, &get_lacnic_as_desc($2, $1)); sleep(10); # LACNIC whois HTTP interface has a "query rate limit"... } } close F2; close F1; } sub get_afrinic_as_desc() { my $asn = $_[0]; my $country = $_[1]; my $asname = ''; my $asdescr = ''; # Note the "query" parameter MUST start with AS contrary to the LACNIC interface open (F35, "wget -q -O - \"http://www.afrinic.net/cgi-bin/whois?query=AS$asn\" |"); while (<F35>) { chop; if (/^as-name:\s+(.+)$/) { $asname = $1; } elsif (/^descr:\s+(.+)$/ && ('' ne $asname)) { $asdescr = $1; last; } } close F35; my $descr = ('' ne $asdescr) ? $asdescr : $asname; $descr = '?' if ('' eq $descr); return "$descr, $country"; } sub make_afrinic() { open (F1, "wget -q -O - ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest |"); open (F2, "> as-afrinic.txt"); print F2 <<EOT; # # This file is generated automatically from # ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest # # Do not edit this file # EOT while (<F1>) { chop; if (/^afrinic\|([A-Z][A-Z])\|asn\|(\d+)\|/) { printf(F2 "%5d\tAFRINIC:%s\n", $2, &get_afrinic_as_desc($2, $1)); } } close F2; close F1; }