-
Notifications
You must be signed in to change notification settings - Fork 12
/
get-asn-names.pl
executable file
·60 lines (54 loc) · 1.32 KB
/
get-asn-names.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
#!/usr/bin/perl -w
# ftp://ftp.ripe.net/ripe/dbase/split/ripe.db.aut-num.gz
use strict;
my (%obj, %x);
my $state = 0;
my $lastobj;
my $lastattr;
while (<>) {
s/[\n\r\s]+$//;
next if /^%/;
s/#.*$//; #?
# print "[$state] $_\n";
if ($state == 0) { # wait for a new record
if (/^$/) {
} elsif (/^aut-num:\s+(\S+)/) {
$lastobj = $1;
$obj{$lastobj} = { };
$state = 1;
} elsif (/^(\S+):/) {
print "DISCARDED: $1\n";
$state = 99;
}
} elsif ($state == 1) {
if (/^$/) {
$state = 0;
} elsif (/^([a-z-]+):(?:\s+(.+))?/) {
my $value = $2 || '';
$lastattr = $1;
# print "<$lastobj><$lastattr>\n";
# use Data::Dumper; print Data::Dumper->Dumpxs([\%obj], ['*obj']);
# BEWARE! This merges multiple attributes!
if (exists $obj{$lastobj}->{$lastattr}) {
$obj{$lastobj}->{$lastattr} .= "\n" . $value;
} else {
$obj{$lastobj}->{$lastattr} .= $value;
}
# XXX what does the + really mean?
} elsif (/^(?:\+?\s+|\+)(.*)/) { # continued attribute
$obj{$lastobj}->{$lastattr} .= "\n" . ($1 || '');
} else {
print STDERR "[$state][$lastobj] $_\n";
die;
}
} elsif ($state == 99) { # eat the current record
if (/^$/) {
$state = 0;
}
} else { die "UNKNOWN STATE: $state" }
}
foreach (keys %obj) {
my $d = $obj{$_}->{descr};
$d =~ s/\n.*$//mg;
print "$_ $obj{$_}->{'as-name'} $d\n";
}