Mercurial > hg > anonet-resdb
annotate contrib/whoisd/whoisd.pl @ 1140:eec8e319f5bd draft
forgot a newline
author | epoch <epoch@hacking.allowed.org> |
---|---|
date | Sun, 06 Oct 2013 11:29:47 +0000 |
parents | c95369b825a2 |
children | 58130f5eecf2 |
rev | line source |
---|---|
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
2 # coded by epoch. |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
3 # use inetd or tcpserver or something else. |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
4 # waste of time to do manual sockets for something like this. |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
5 # this isn't my baby. you can murder it if you want. |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
6 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
7 use strict; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
8 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
9 my $RESDB = "/services/resdb/resdb"; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
10 |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
11 my $HACK=0; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
12 my $QUERY=<stdin>; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
13 $QUERY =~ s/\r\n//g; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
14 my $out; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
15 my $title; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
16 my $value; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
17 my @parts; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
18 my $i; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
19 |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
20 if($QUERY eq "!!\n") { |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
21 $QUERY=<stdin>; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
22 $QUERY =~ s/^!r(.+?)[\/,].*$/\1/; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
23 printf "A500\n"; #fake this I guess. Does it even use that number for anything? |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
24 printf "%% Looks like you're trying -A on a BSDian traceroute with this server.\n"; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
25 printf "%% support will come soon for that.\n"; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
26 $HACK=1; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
27 } |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
28 |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
29 # ASNs |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
30 if($QUERY =~ m/^AS(.+?)$/) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
31 printf "%% AS section for %s\n", $QUERY; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
32 my $AS=$1; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
33 chdir("$RESDB/db/as"); |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
34 if(chdir($AS)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
35 foreach(split(/\n/,`grep '' -r .`)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
36 $out = $_; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
37 $out =~ s/^\.\///g; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
38 $out =~ m/^(.+?):(.+?)$/; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
39 ($title, $value) = ($1, $2); |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
40 printf "%-20s %s\n", $title . ":", $value; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
41 if($title eq "owner") { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
42 $QUERY = $value; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
43 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
44 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
45 } else { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
46 printf "AS not found."; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
47 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
48 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
49 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
50 # IPv4 addresses |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
51 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]?)$/) { |
1140 | 52 printf "%% IP section for %s\n", $QUERY unless $HACK; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
53 chdir("$RESDB/db/ip"); |
1133
1a5d655cae9c
fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents:
1132
diff
changeset
|
54 @parts=split(/\./,$QUERY); |
1a5d655cae9c
fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents:
1132
diff
changeset
|
55 for($i=0;$i<scalar(@parts)-1;$i++) { |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
56 if(!chdir(sprintf("%02X",$parts[$i]))) { |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
57 printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK; |
1133
1a5d655cae9c
fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents:
1132
diff
changeset
|
58 exit; |
1a5d655cae9c
fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents:
1132
diff
changeset
|
59 } |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
60 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
61 foreach(split(/\n/,`grep '' -r .`)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
62 $out = $_; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
63 $out =~ s/^\.\///g; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
64 ($title, $value) = split(/:/,$out); |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
65 printf "%-20s %s\n", $title . ":", $value unless $HACK; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
66 if($title eq "owner") { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
67 $QUERY = $value; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
68 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
69 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
70 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
71 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
72 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
73 # if we get here and there's still a . in the query it is probably a domain. |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
74 if($QUERY =~ m/\./) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
75 printf "%% domain section for %s\n", $QUERY; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
76 @parts=split(/\./,$QUERY); |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
77 chdir("$RESDB/db/dom"); |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
78 for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) { |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
79 if(!chdir($parts[$i])) { |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
80 printf "%-20s %s", "warning" . ":", "domain not found."; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
81 exit; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
82 } |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
83 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
84 foreach(split(/\n/,`grep '' -r .`)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
85 $out = $_; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
86 $out =~ s/^\.\///g; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
87 $out =~ m/^(.+?):(.+?)$/; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
88 ($title, $value) = ($1, $2); |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
89 printf "%-20s %s\n", $title . ":", $value; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
90 if($title eq "owner") { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
91 $QUERY = $value; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
92 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
93 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
94 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
95 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
96 # default to assuming it is a name. |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
97 printf "%% user section for %s\n", $QUERY unless $HACK; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
98 |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
99 chdir("$RESDB/db/usr"); |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
100 if(chdir($QUERY)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
101 foreach(split(/\n/,`grep '' -r .`)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
102 $out = $_; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
103 $out =~ s/^\.\///g; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
104 $out =~ m/^(.+?):(.+?)$/; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
105 ($title, $value) = ($1, $2); |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
106 printf "%-20s %s\n", $title . ":", $value unless $HACK; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
107 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
108 } else { |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
109 printf "%-20s missing db/usr file.\n", "warning" . ":" unless $HACK; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
110 } |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
111 chdir("$RESDB/db/as"); |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
112 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
113 $out = $_; |
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
114 $out =~ s/\n//g; |
1138
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
115 printf "%-20s AS%s\n", "origin" . ":", $out if $HACK; |
c95369b825a2
whoisd... don't remember.
epoch <epoch@hacking.allowed.org>
parents:
1133
diff
changeset
|
116 printf "%-20s AS%s\n", "origin" . ":", $out unless $HACK; |
1131
16cef39f682d
Added a whoisd to make for easier querying of the resdb's info. Read the source.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
117 } |
1132 | 118 |
119 foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) { | |
120 $out = $_; | |
121 $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/; | |
122 if ($out ne "") { #fix this comparison. | |
123 printf "%-20s %s\n", "domain" . ":", $out; | |
124 } | |
125 } | |
126 #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet"; |