-
Notifications
You must be signed in to change notification settings - Fork 32
/
makeaslist.pl
executable file
·222 lines (185 loc) · 4.45 KB
/
makeaslist.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/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;
}