3 ## Read BGPd logfile and lookup RR's whois database.
5 ## Copyright (c) 1997 Kunihiro Ishiguro
9 ## Configuration variables
10 $whois_host = "whois.jpix.ad.jp";
12 #$mail_address = "toshio\@iri.co.jp";
13 $mail_address = "kunihiro\@zebra.org";
14 $mailer = "/usr/sbin/sendmail -oi";
16 #$logfile = "/usr/local/sbin/logfile"
18 $lookuplog = "lookuplog";
22 local ($prefix, $origin);
24 open (LOG
, $logfile) || die "can't open $logfile";
25 open (LOOKUP
, ">$lookuplog") || die "can't open $lookuplog";
29 if (/Update\S+ ([\d\.\/]+) .* (\d
+) [ie
\?]/) {
32 $ret = &whois_check
($prefix, $origin);
34 print LOOKUP
"$prefix AS$origin : Check OK\n";
36 print LOOKUP
"$prefix AS$origin : Error\n";
47 local ($prefix, $origin) = @_;
48 local ($rr_prefix, $rr_origin) = ();
51 $origin = "AS" . $origin;
53 # print "$prefix $origin\n";
55 @result = &whois
($prefix);
58 if (/^route:.*\s([\d\.\/]+)$/) {
61 if (/^origin:.*\s(AS[\d]+)$/) {
64 if ($prefix eq $rr_prefix and $origin eq $rr_origin) {
69 alarm_mail
($prefix, $origin, @result);
76 local ($name, $aliases, $port, $proto) = getservbyname ("whois", "tcp");
77 return ($port, $proto);
84 local ($port, $proto) = &get_whois_port
;
87 if ($whois_host=~ /^\s*\d+\.\d+\.\d+\.\d+\s*$/) {
88 $address = pack ("C4",split(/\./,$host));
90 $address = (gethostbyname ($whois_host))[4];
93 socket (SOCKET
, PF_INET
, SOCK_STREAM
, $proto);
95 if (connect (SOCKET
, sockaddr_in
($port, $address))) {
96 local ($oldhandle) = select (SOCKET
);
100 print SOCKET
"$query\r\n";
110 local ($prefix, $origin, @result) = @_;
112 open (MAIL
, "|$mailer -t $mail_address") || die "can't open $mailer";
114 print MAIL
"From: root\@rr1.jpix.ad.jp\n";
115 print MAIL
"Subject: RR $origin $prefix\n";
116 print MAIL
"MIME-Version: 1.0\n";
117 print MAIL
"Content-Type: text/plain; charset=us-ascii \n\n";
118 print MAIL
"RR Lookup Error Report\n";
119 print MAIL
"======================\n";
120 print MAIL
"Announced route : $prefix from $origin\n\n";
121 print MAIL
"@result";