From 1c0dfe1d6fbd33f24da3e8bad01acbb7565e6d3d Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 1 Nov 2013 09:12:45 +0000 Subject: Added mkz to anonet and as many of the needed files as I could think of. That as.c is the part of NetBSD traceroute that does AS lookups. --- contrib/whoisd/whoisd.pl | 122 +++++++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 42 deletions(-) (limited to 'contrib/whoisd/whoisd.pl') diff --git a/contrib/whoisd/whoisd.pl b/contrib/whoisd/whoisd.pl index 67636c9..e1854a0 100755 --- a/contrib/whoisd/whoisd.pl +++ b/contrib/whoisd/whoisd.pl @@ -31,27 +31,30 @@ if($QUERY eq "!!\n") { $HACK=1; } -# ASNs -if($QUERY =~ m/^AS(.+?)$/) { - printf "%% AS section for %s\n", $QUERY; - my $AS=$1; - chdir("$RESDB/db/as") || die "%% error"; - if(chdir($AS) || die "%% error") { - foreach(split(/\n/,`grep '' -r .`)) { - $out = $_; - $out =~ s/^\.\///g; - $out =~ m/^(.+?):(.+?)$/; - ($title, $value) = ($1, $2); - printf "%-20s %s\n", $title . ":", $value; - if($title eq "owner") { - $QUERY = $value; +sub ASN_lookup { + if($QUERY =~ m/^AS(.+?)$/) { + printf "%% AS section for %s\n", $QUERY; + my $AS=$1; + chdir("$RESDB/db/as") || die "%% error"; + if(chdir($AS) || die "%% error") { + foreach(split(/\n/,`grep '' -r .`)) { + $out = $_; + $out =~ s/^\.\///g; + $out =~ m/^(.+?):(.+?)$/; + ($title, $value) = ($1, $2); + printf "%-20s %s\n", $title . ":", $value; + if($title eq "owner") { + $QUERY = $value; + } } + } else { + printf "AS not found."; } - } else { - printf "AS not found."; } } +ASN_lookup(); + # IPv4 addresses if($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) { printf "%% IP section for %s\n", $QUERY unless $HACK; @@ -74,7 +77,6 @@ if($QUERY =~ m/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0- } } - # if we get here and there's still a . in the query it is probably a domain. if($QUERY =~ m/\./) { printf "%% domain section for %s\n", $QUERY; @@ -102,34 +104,70 @@ if($QUERY =~ m/\./) { } } +#ipv6 addresses +#if($QUERY =~ m/:/) {#close enough? +# $QUERY =~ s/://g; +# $QUERY =~ s/[^a-fA-F0-9]//g; +# $QUERY = uc($QUERY); +# chdir("$RESDB/db/ip6"); +# foreach(split(//,$QUERY)) { +# chdir($_);; +# } +# foreach(split(/\n/,`grep '' -r .`)) { +# $out = $_; +# $out =~ s/^\.\///g; +# $out =~ m/^(.+?):(.+?)$/; +# ($title, $value) = ($1, $2); +# printf "%-20s %s\n", $title . ":", $value; +# if($title eq "owner") { +# $QUERY = $value; +# } +# } +#} + + # default to assuming it is a name. -printf "%% user section for '%s'\n", $QUERY unless $HACK; + printf "%% user section for '%s'\n", $QUERY unless $HACK; -chdir("$RESDB/db/usr") || die "%% error"; -if(chdir($QUERY)) { - foreach(split(/\n/,`grep '' -r .`)) { + chdir("$RESDB/db/usr") || die "%% error"; + if(chdir($QUERY)) { + foreach(split(/\n/,`grep '' -r .`)) { + $out = $_; + $out =~ s/^\.\///g; + $out =~ m/^(.+?):(.+?)$/; + ($title, $value) = ($1, $2); + printf "%-20s %s\n", $title . ":", $value unless $HACK; + } + } else { + printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK; + } + chdir("$RESDB/db/as") || die "%% error"; + my @asn; + foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { $out = $_; - $out =~ s/^\.\///g; - $out =~ m/^(.+?):(.+?)$/; - ($title, $value) = ($1, $2); - printf "%-20s %s\n", $title . ":", $value unless $HACK; + $out =~ s/\n//g; + printf "%-20s AS%s\n", "origin" . ":", $out if $HACK; + printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK; + @asn[scalar(@asn)]=$out; + } + chdir("$RESDB/db/ip") || die "%% error"; + my $merp; + foreach(split(/\n/,`grep '^$QUERY\$' */*/*/owner | cut -d/ -f1-3`)) { + $merp=`cat $_/cidr`; + chomp $merp; + printf "%-20s %s\n", "cidr" . ":", $merp; + } + + foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) { + $out = $_; + $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/; + if ($out ne "") { #fix this comparison. + printf "%-20s %s\n", "domain" . ":", $out; + } } -} else { - printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK; -} -chdir("$RESDB/db/as") || die "%% error"; -foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { - $out = $_; - $out =~ s/\n//g; - printf "%-20s AS%s\n", "origin" . ":", $out if $HACK; - printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK; -} -foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) { - $out = $_; - $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/; - if ($out ne "") { #fix this comparison. - printf "%-20s %s\n", "domain" . ":", $out; + foreach(@asn) { + $QUERY="AS$_"; #meh. fix to pass it instead of global. + ASN_lookup(); } -} -#printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet"; + #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet"; -- cgit v1.2.3