Mercurial > hg > anonet-resdb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1127:3bbc40562b66 | 1131:16cef39f682d |
---|---|
1 #!/usr/bin/perl | |
2 # coded by epoch. | |
3 # use inetd or tcpserver or something else. | |
4 # waste of time to do manual sockets for something like this. | |
5 # this isn't my baby. you can murder it if you want. | |
6 | |
7 use strict; | |
8 | |
9 my $RESDB = "/services/resdb/resdb"; | |
10 | |
11 my $QUERY=<stdin>; | |
12 $QUERY =~ s/\r\n//g; | |
13 my $out; | |
14 my $title; | |
15 my $value; | |
16 my @parts; | |
17 my $i; | |
18 | |
19 # ASNs | |
20 if($QUERY =~ m/^AS(.+?)$/) { | |
21 printf "%% AS section for %s\n", $QUERY; | |
22 my $AS=$1; | |
23 chdir("$RESDB/db/as"); | |
24 if(chdir($AS)) { | |
25 foreach(split(/\n/,`grep '' -r .`)) { | |
26 $out = $_; | |
27 $out =~ s/^\.\///g; | |
28 $out =~ m/^(.+?):(.+?)$/; | |
29 ($title, $value) = ($1, $2); | |
30 printf "%-20s %s\n", $title . ":", $value; | |
31 if($title eq "owner") { | |
32 $QUERY = $value; | |
33 } | |
34 } | |
35 } else { | |
36 printf "AS not found."; | |
37 } | |
38 } | |
39 | |
40 # IPv4 addresses | |
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]?)$/) { | |
42 printf "%% IP section for %s\n", $QUERY; | |
43 chdir("$RESDB/db/ip"); | |
44 foreach(split(/\./,$QUERY)) { | |
45 chdir(sprintf("%02x",$_)); | |
46 } | |
47 foreach(split(/\n/,`grep '' -r .`)) { | |
48 $out = $_; | |
49 $out =~ s/^\.\///g; | |
50 ($title, $value) = split(/:/,$out); | |
51 printf "%-20s %s\n", $title . ":", $value; | |
52 if($title eq "owner") { | |
53 $QUERY = $value; | |
54 } | |
55 } | |
56 } | |
57 | |
58 | |
59 # if we get here and there's still a . in the query it is probably a domain. | |
60 if($QUERY =~ m/\./) { | |
61 printf "%% domain section for %s\n", $QUERY; | |
62 @parts=split(/\./,$QUERY); | |
63 chdir("$RESDB/db/dom"); | |
64 for($i=scalar(@parts)-1;$i>=0;$i--) { | |
65 chdir($parts[$i]); | |
66 } | |
67 foreach(split(/\n/,`grep '' -r .`)) { | |
68 $out = $_; | |
69 $out =~ s/^\.\///g; | |
70 $out =~ m/^(.+?):(.+?)$/; | |
71 ($title, $value) = ($1, $2); | |
72 printf "%-20s %s\n", $title . ":", $value; | |
73 if($title eq "owner") { | |
74 $QUERY = $value; | |
75 } | |
76 } | |
77 } | |
78 | |
79 # default to assuming it is a name. | |
80 printf "%% user section for %s\n", $QUERY; | |
81 | |
82 chdir("$RESDB/db/usr"); | |
83 if(chdir($QUERY)) { | |
84 foreach(split(/\n/,`grep '' -r .`)) { | |
85 $out = $_; | |
86 $out =~ s/^\.\///g; | |
87 $out =~ m/^(.+?):(.+?)$/; | |
88 ($title, $value) = ($1, $2); | |
89 printf "%-20s %s\n", $title . ":", $value; | |
90 } | |
91 } else { | |
92 printf "%-20s missing db/usr file.\n", "warning" . ":"; | |
93 } | |
94 chdir("$RESDB/db/as"); | |
95 foreach(split(/\n/,`grep '^$QUERY\$' */owner | cut -d/ -f1`)) { | |
96 $out = $_; | |
97 $out =~ s/\n//g; | |
98 printf "%-20s %s\n", "ASN" . ":", $out; | |
99 } |