annotate contrib/whoisd/whoisd.pl @ 1131:16cef39f682d draft

Added a whoisd to make for easier querying of the resdb's info. Read the source.
author epoch <epoch@hacking.allowed.org>
date Fri, 23 Aug 2013 03:24:54 +0000
parents
children 2fd95bea3988
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");
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 foreach(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
45 chdir(sprintf("%02x",$_));
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 }
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 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
48 $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
49 $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
50 ($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
51 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
52 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
53 $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
54 }
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 }
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 }
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
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 # 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
60 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
61 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
62 @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
63 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
64 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
65 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
66 }
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 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
68 $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
69 $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
70 $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
71 ($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
72 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
73 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
74 $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
75 }
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 }
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 }
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
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 # 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
80 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
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 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
83 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
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 }
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 } 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
92 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
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 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
95 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
96 $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
97 $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
98 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
99 }