annotate contrib/whoisd/whoisd.pl @ 1133:1a5d655cae9c draft

fixed another bug in whoisd
author epoch <epoch@hacking.allowed.org>
date Fri, 23 Aug 2013 18:43:12 +0000
parents 2fd95bea3988
children c95369b825a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
11 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
12 $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
13 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
14 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
15 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
16 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
17 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
18
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 # 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
20 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
21 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
22 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
23 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
24 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
25 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
26 $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
27 $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
28 $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
29 ($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
30 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
31 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
32 $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
33 }
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 }
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 } 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
36 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
37 }
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 }
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
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 # 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
41 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]?)$/) {
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 printf "%% IP 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
43 chdir("$RESDB/db/ip");
1133
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
44 @parts=split(/\./,$QUERY);
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
45 for($i=0;$i<scalar(@parts)-1;$i++) {
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
46 if(!chdir(sprintf("%02x",$parts[$i]))) {
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
47 printf "%-20s %s\n", "error" . ":", "IP not found.";
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
48 exit;
1a5d655cae9c fixed another bug in whoisd
epoch <epoch@hacking.allowed.org>
parents: 1132
diff changeset
49 }
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
50 }
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 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
52 $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
53 $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
54 ($title, $value) = split(/:/,$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
55 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
56 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
57 $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
58 }
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
59 }
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
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
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 # 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
64 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
65 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
66 @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
67 chdir("$RESDB/db/dom");
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 for($i=scalar(@parts)-1;$i>=0;$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
69 chdir($parts[$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
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 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
72 $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
73 $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
74 $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
75 ($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
76 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
77 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
78 $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
79 }
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
80 }
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
81 }
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
82
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 # default to assuming it is a name.
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 printf "%% user 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
85
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 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
87 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
88 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
89 $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
90 $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
91 $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
92 ($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
93 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
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 } 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
96 printf "%-20s missing db/usr file.\n", "warning" . ":";
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
97 }
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 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
99 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
100 $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
101 $out =~ s/\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
102 printf "%-20s %s\n", "ASN" . ":", $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 }
1132
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
104
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
105 foreach(split(/\n/,`grep -i -e "^$QUERY\$" "$RESDB/db/dom"/*/*/owner`)) {
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
106 $out = $_;
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
107 $out =~ s/.*\/db\/dom\/(.+?)\/(.+?)\/owner.*/\2\.\1/;
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
108 if ($out ne "") { #fix this comparison.
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
109 printf "%-20s %s\n", "domain" . ":", $out;
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
110 }
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
111 }
2fd95bea3988 updated whoid
epoch <epoch@hacking.allowed.org>
parents: 1131
diff changeset
112 #printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet";