summaryrefslogtreecommitdiff
path: root/contrib/whoisd/whoisd.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/whoisd/whoisd.pl')
-rwxr-xr-xcontrib/whoisd/whoisd.pl230
1 files changed, 167 insertions, 63 deletions
diff --git a/contrib/whoisd/whoisd.pl b/contrib/whoisd/whoisd.pl
index 107f7ea..60ce11f 100755
--- a/contrib/whoisd/whoisd.pl
+++ b/contrib/whoisd/whoisd.pl
@@ -1,8 +1,6 @@
#!/usr/bin/perl
-# coded by epoch.
-# use inetd or tcpserver or something else.
-# waste of time to do manual sockets for something like this.
-# this isn't my baby. you can murder it if you want.
+# ncat -klp 43 -e ./whoisd.pl
+# use inetd or tcpserver or ncat
use strict;
@@ -23,6 +21,9 @@ my $value;
my @value;
my @parts;
my $i;
+my $d;
+
+my $user;
if($QUERY eq "!!\n") {
$QUERY=<stdin>;
@@ -32,6 +33,75 @@ if($QUERY eq "!!\n") {
$HACK=1;
}
+sub get_user_from_ASN {
+ my $AS=$_[0];
+ my $user;
+ chdir("$RESDB/db/as") || die "%% error";
+ if(chdir($AS) || die "%% error") {
+ open(FILE,"owner") || die "%% ASN not found.";
+ $user=<FILE>;
+ close(FILE);
+ } else {
+ printf "%% AS not found.";
+ }
+ return $user;
+}
+
+sub get_user_from_IPv4 {
+ my @parts;
+ my $user;
+ chdir("$RESDB/db/ip") || die "%% error";
+ @parts=split(/\./,$_[0]);
+ for($i=0;$i<scalar(@parts)-1;$i++) {
+ if(!chdir(sprintf("%02X",$parts[$i]))) {
+ printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK;
+ exit;
+ }
+ }
+ open(FILE,"owner") || die "%% IP not found.";
+ $user=<FILE>;
+ close(FILE);
+ return $user;
+}
+
+sub get_user_from_domain {
+ my @parts;
+ my $user;
+ my $i;
+ @parts=split(/\./,$_[0]);
+ chdir("$RESDB/db/dom") || die "%% error";
+ for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) {
+ if(!$parts[$i]) {
+ printf "%% error";
+ exit
+ }
+ if(!chdir($parts[$i])) {
+ printf "%-20s %s", "warning" . ":", "domain not found.";
+ exit;
+ }
+ }
+ open(FILE,"owner") || die "%% IP's owner not found.";
+ $user=<FILE>;
+ close(FILE);
+ return $user;
+}
+
+sub get_user_from_IPv6 {
+ chdir("$RESDB/db/ip6") || die "%% error. no resdb/db/ip6\n";
+ $d=$_[0];
+ print "$d";
+ $d =~ s/[^0-9a-f]//gi;
+ $d =~ tr/a-z/A-Z/;
+ foreach(split(//,$d)) {
+ $d=$_;
+ chdir($d);
+ }
+ open(FILE,"owner") || die "%% IP6's owner not found.";
+ $user=<FILE>;
+ close(FILE);
+ return $user;
+}
+
sub ASN_lookup {
if($QUERY =~ m/^AS(.+?)$/) {
printf "%% AS section for %s\n", $QUERY;
@@ -54,81 +124,88 @@ sub ASN_lookup {
}
}
-ASN_lookup();
# IPv4 addresses
-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]?)$/) {
- printf "%% IP section for %s\n", $QUERY unless $HACK;
- chdir("$RESDB/db/ip") || die "%% error";
- @parts=split(/\./,$QUERY);
- for($i=0;$i<scalar(@parts)-1;$i++) {
- if(!chdir(sprintf("%02X",$parts[$i]))) {
- printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK;
- exit;
+sub IPv4_lookup {
+ 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]?)$/) {
+ printf "%% IP section for %s\n", $QUERY unless $HACK;
+ chdir("$RESDB/db/ip") || die "%% error";
+ @parts=split(/\./,$QUERY);
+ for($i=0;$i<scalar(@parts)-1;$i++) {
+ if(!chdir(sprintf("%02X",$parts[$i]))) {
+ printf "%-20s %s\n", "error" . ":", "IP not found." unless $HACK;
+ exit;
+ }
}
- }
- foreach(split(/\n/,`grep '' -r .`)) {
- $out = $_;
- $out =~ s/^\.\///g;
- ($title, @value) = split(/:/,$out);
- $value=join(":",@value);
- printf "%-20s %s\n", $title . ":", $value unless $HACK;
- if($title eq "owner") {
- $QUERY = $value;
+ foreach(split(/\n/,`grep '' -r .`)) {
+ $out = $_;
+ $out =~ s/^\.\///g;
+ ($title, @value) = split(/:/,$out);
+ $value=join(":",@value);
+ printf "%-20s %s\n", $title . ":", $value unless $HACK;
+ if($title eq "owner") {
+ $QUERY = $value ;
+ }
}
}
}
+
# if we get here and there's still a . in the query it is probably a domain.
-if($QUERY =~ m/\./) {
- printf "%% domain section for %s\n", $QUERY;
- @parts=split(/\./,$QUERY);
- chdir("$RESDB/db/dom") || die "%% error";
- for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) {
- if(!$parts[$i]) {
- printf "%% error";
- exit
- }
- if(!chdir($parts[$i])) {
- printf "%-20s %s", "warning" . ":", "domain not found.";
- exit;
+sub domain_lookup {
+ if($QUERY =~ m/\./) {
+ printf "%% domain section for %s\n", $QUERY;
+ @parts=split(/\./,$QUERY);
+ chdir("$RESDB/db/dom") || die "%% error";
+ for($i=scalar(@parts)-1;$i>scalar(@parts)-3;$i--) {
+ if(!$parts[$i]) {
+ printf "%% error";
+ exit
+ }
+ if(!chdir($parts[$i])) {
+ printf "%-20s %s", "warning" . ":", "domain not found.";
+ exit;
+ }
}
- }
- foreach(split(/\n/,`grep '' -r .`)) {
- $out = $_;
- $out =~ s/^\.\///g;
- $out =~ m/^(.+?):(.+?)$/;
- ($title, $value) = ($1, $2);
- printf "%-20s %s\n", $title . ":", $value;
- if($title eq "owner") {
- $QUERY = $value;
+ foreach(split(/\n/,`grep '' -r .`)) {
+ $out = $_;
+ $out =~ s/^\.\///g;
+ $out =~ m/^(.+?):(.+?)$/;
+ ($title, $value) = ($1, $2);
+ printf "%-20s %s\n", $title . ":", $value;
+ if($title eq "owner") {
+ $QUERY = $value;
+ }
}
}
}
-#ipv6 addresses
-#if($QUERY =~ m/:/) {#close enough?
-# $QUERY =~ s/://g;
-# $QUERY =~ s/[^a-fA-F0-9]//g;
-# $QUERY = uc($QUERY);
-# chdir("$RESDB/db/ip6");
-# foreach(split(//,$QUERY)) {
-# chdir($_);;
-# }
-# foreach(split(/\n/,`grep '' -r .`)) {
-# $out = $_;
-# $out =~ s/^\.\///g;
-# $out =~ m/^(.+?):(.+?)$/;
-# ($title, $value) = ($1, $2);
-# printf "%-20s %s\n", $title . ":", $value;
-# if($title eq "owner") {
-# $QUERY = $value;
-# }
-# }
-#}
+#IPv6 addresses
+sub IPv6_lookup {
+ if($QUERY =~ m/:/) {#close enough?
+ $QUERY =~ s/://g;
+ $QUERY =~ s/[^a-fA-F0-9]//g;
+ $QUERY = uc($QUERY);
+ chdir("$RESDB/db/ip6");
+ foreach(split(//,$QUERY)) {
+ chdir($_);;
+ }
+ foreach(split(/\n/,`grep '' -r .`)) {
+ $out = $_;
+ $out =~ s/^\.\///g;
+ $out =~ m/^(.+?):(.+?)$/;
+ ($title, $value) = ($1, $2);
+ printf "%-20s %s\n", $title . ":", $value;
+ if($title eq "owner") {
+ $QUERY = $value;
+ }
+ }
+ }
+}
# default to assuming it is a name.
+sub user_lookup {
printf "%% user section for '%s'\n", $QUERY unless $HACK;
chdir("$RESDB/db/usr") || die "%% error";
@@ -173,3 +250,30 @@ if($QUERY =~ m/\./) {
ASN_lookup();
}
#printf "%-20s %s\n", "notice:","$QUERY did not claim any domains yet";
+}
+
+if($QUERY =~ m/^AS(.+?)$/) {
+ $user=get_user_from_ASN($1);
+}
+elsif($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]?)$/) {
+ $user=get_user_from_IPv4($QUERY);
+}
+elsif($QUERY =~ m/\./) {
+ $user=get_user_from_domain($QUERY);
+}
+elsif($QUERY =~ m/:/) {
+ $user=get_user_from_IPv6($QUERY);
+}
+else {
+ $user=$QUERY;
+}
+$user =~ s/[\r\n]//g;
+printf "%%%% found user: %s for the query.\n", $user;
+
+#k. we got user... now to find stuff belonging to that user.
+
+#ASN_lookup($user);
+#IPv4_lookup($user);
+#domain_lookup($user);
+#IPv6_lookup($user);
+user_lookup();