]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/DNS.pl
Initial revision
[infobot.git] / src / Modules / DNS.pl
1
2 # infobot :: Kevin Lenzo  (c) 1997
3
4 # once again, thanks to Patrick Cole
5
6 #use POSIX;
7 use Socket;
8 use strict;
9
10 use vars qw($waitedpid);
11
12 sub REAPER {
13         $SIG{CHLD} = \&REAPER;  # loathe sysV
14         $waitedpid = wait;
15 }
16
17 $SIG{CHLD} = \&REAPER;
18
19 sub DNS {
20     my $in = $_[0];
21     my($match, $x, $y, $result);
22     my $pid;
23
24     if (!defined($pid = fork)) {
25         return "no luck, $who";
26     } elsif ($pid) {
27         # parent
28     } else {
29         # child
30         if ($in =~ /(\d+\.\d+\.\d+\.\d+)/) {
31             &status("DNS query by IP address: $in");
32             $match = $1;
33             $y = pack('C4', split(/\./, $match));
34             $x = (gethostbyaddr($y, &AF_INET));
35             if ($x !~ /^\s*$/) {
36                 $result = $match." is ".$x unless ($x =~ /^\s*$/);
37             } else {
38                 $result = "I can't seem to find that address in DNS";
39             }
40         } else {
41             &status("DNS query by name: $in");
42             $x = join('.',unpack('C4',(gethostbyname($in))[4]));
43             if ($x !~ /^\s*$/) {
44                 $result = $in." is ".$x;
45             } else {
46                 $result = "I can\'t find that machine name";
47             }
48         }
49
50         if ($msgType eq 'public') {
51             &say($result);
52         } else {
53             &msg($who, $result);
54         }
55         exit;                   # bye child
56     }
57 }
58
59 1;