comparison contrib/whoisd/whoisd.pl @ 1146:da853b90f62b draft

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.
author epoch <epoch@hacking.allowed.org>
date Fri, 01 Nov 2013 09:12:45 +0000
parents ca4d35064aa2
children 1112129d9653
comparison
equal deleted inserted replaced
1145:b19ced4435be 1146:da853b90f62b
29 printf "A500\n"; #fake this I guess. Does it even use that number for anything? 29 printf "A500\n"; #fake this I guess. Does it even use that number for anything?
30 printf "%% Looks like you're trying -A on a BSDian traceroute with this server.\n"; 30 printf "%% Looks like you're trying -A on a BSDian traceroute with this server.\n";
31 $HACK=1; 31 $HACK=1;
32 } 32 }
33 33
34 # ASNs 34 sub ASN_lookup {
35 if($QUERY =~ m/^AS(.+?)$/) { 35 if($QUERY =~ m/^AS(.+?)$/) {
36 printf "%% AS section for %s\n", $QUERY; 36 printf "%% AS section for %s\n", $QUERY;
37 my $AS=$1; 37 my $AS=$1;
38 chdir("$RESDB/db/as") || die "%% error"; 38 chdir("$RESDB/db/as") || die "%% error";
39 if(chdir($AS) || die "%% error") { 39 if(chdir($AS) || die "%% error") {
40 foreach(split(/\n/,`grep '' -r .`)) { 40 foreach(split(/\n/,`grep '' -r .`)) {
41 $out = $_; 41 $out = $_;
42 $out =~ s/^\.\///g; 42 $out =~ s/^\.\///g;
43 $out =~ m/^(.+?):(.+?)$/; 43 $out =~ m/^(.+?):(.+?)$/;
44 ($title, $value) = ($1, $2); 44 ($title, $value) = ($1, $2);
45 printf "%-20s %s\n", $title . ":", $value; 45 printf "%-20s %s\n", $title . ":", $value;
46 if($title eq "owner") { 46 if($title eq "owner") {
47 $QUERY = $value; 47 $QUERY = $value;
48 }
48 } 49 }
50 } else {
51 printf "AS not found.";
49 } 52 }
50 } else {
51 printf "AS not found.";
52 } 53 }
53 } 54 }
55
56 ASN_lookup();
54 57
55 # IPv4 addresses 58 # IPv4 addresses
56 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]?)$/) { 59 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]?)$/) {
57 printf "%% IP section for %s\n", $QUERY unless $HACK; 60 printf "%% IP section for %s\n", $QUERY unless $HACK;
58 chdir("$RESDB/db/ip") || die "%% error"; 61 chdir("$RESDB/db/ip") || die "%% error";
71 if($title eq "owner") { 74 if($title eq "owner") {
72 $QUERY = $value; 75 $QUERY = $value;
73 } 76 }
74 } 77 }
75 } 78 }
76
77 79
78 # if we get here and there's still a . in the query it is probably a domain. 80 # if we get here and there's still a . in the query it is probably a domain.
79 if($QUERY =~ m/\./) { 81 if($QUERY =~ m/\./) {
80 printf "%% domain section for %s\n", $QUERY; 82 printf "%% domain section for %s\n", $QUERY;
81 @parts=split(/\./,$QUERY); 83 @parts=split(/\./,$QUERY);
100 $QUERY = $value; 102 $QUERY = $value;
101 } 103 }
102 } 104 }
103 } 105 }
104 106
107 #ipv6 addresses
108 #if($QUERY =~ m/:/) {#close enough?
109 # $QUERY =~ s/://g;
110 # $QUERY =~ s/[^a-fA-F0-9]//g;
111 # $QUERY = uc($QUERY);
112 # chdir("$RESDB/db/ip6");
113 # foreach(split(//,$QUERY)) {
114 # chdir($_);;
115 # }
116 # foreach(split(/\n/,`grep '' -r .`)) {
117 # $out = $_;
118 # $out =~ s/^\.\///g;
119 # $out =~ m/^(.+?):(.+?)$/;
120 # ($title, $value) = ($1, $2);
121 # printf "%-20s %s\n", $title . ":", $value;
122 # if($title eq "owner") {
123 # $QUERY = $value;
124 # }
125 # }
126 #}
127
128
105 # default to assuming it is a name. 129 # default to assuming it is a name.
106 printf "%% user section for '%s'\n", $QUERY unless $HACK; 130 printf "%% user section for '%s'\n", $QUERY unless $HACK;
107 131
108 chdir("$RESDB/db/usr") || die "%% error"; 132 chdir("$RESDB/db/usr") || die "%% error";
109 if(chdir($QUERY)) { 133 if(chdir($QUERY)) {
110 foreach(split(/\n/,`grep '' -r .`)) { 134 foreach(split(/\n/,`grep '' -r .`)) {
135 $out = $_;
136 $out =~ s/^\.\///g;
137 $out =~ m/^(.+?):(.+?)$/;
138 ($title, $value) = ($1, $2);
139 printf "%-20s %s\n", $title . ":", $value unless $HACK;
140 }
141 } else {
142 printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK;
143 }
144 chdir("$RESDB/db/as") || die "%% error";
145 my @asn;
146 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) {
111 $out = $_; 147 $out = $_;
112 $out =~ s/^\.\///g; 148 $out =~ s/\n//g;
113 $out =~ m/^(.+?):(.+?)$/; 149 printf "%-20s AS%s\n", "origin" . ":", $out if $HACK;
114 ($title, $value) = ($1, $2); 150 printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK;
115 printf "%-20s %s\n", $title . ":", $value unless $HACK; 151 @asn[scalar(@asn)]=$out;
116 } 152 }
117 } else { 153 chdir("$RESDB/db/ip") || die "%% error";
118 printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK; 154 my $merp;
119 } 155 foreach(split(/\n/,`grep '^$QUERY\$' */*/*/owner | cut -d/ -f1-3`)) {
120 chdir("$RESDB/db/as") || die "%% error"; 156 $merp=`cat $_/cidr`;
121 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { 157 chomp $merp;
122 $out = $_; 158 printf "%-20s %s\n", "cidr" . ":", $merp;
123 $out =~ s/\n//g; 159 }
124 printf "%-20s AS%s\n", "origin" . ":", $out if $HACK; 160
125 printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK; 161 foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) {
126 } 162 $out = $_;
163 $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/;
164 if ($out ne "") { #fix this comparison.
165 printf "%-20s %s\n", "domain" . ":", $out;
166 }
167 }
127 168
128 foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) { 169 foreach(@asn) {
129 $out = $_; 170 $QUERY="AS$_"; #meh. fix to pass it instead of global.
130 $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/; 171 ASN_lookup();
131 if ($out ne "") { #fix this comparison.
132 printf "%-20s %s\n", "domain" . ":", $out;
133 } 172 }
134 } 173 #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet";
135 #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet";