]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/dns.pl
* Merge back with trunk to r1810
[infobot.git] / src / Modules / dns.pl
1 #
2 #     dns.pl: host lookups
3 #     Author: Tim Riker <Tim@Rikers.org>
4 #     Source: extracted from UserExtra.pl
5 #  Licensing: Artistic License (as perl itself)
6 #    Version: v0.1
7 #
8 #  Copyright (c) 2005 Tim Riker
9 #
10
11 package dns;
12
13 use strict;
14
15 sub dns::dns {
16     my $dns = shift;
17     my ( $match, $x, $y, $result, $pid );
18
19     if ( $dns =~ /(\d+\.\d+\.\d+\.\d+)/ ) {
20         use Socket;
21
22         &::status("DNS query by IP address: $dns");
23
24         $y = pack( 'C4', split( /\./, $dns ) );
25         $x = ( gethostbyaddr( $y, &AF_INET ) );
26
27         if ( $x !~ /^\s*$/ ) {
28             $result = "$dns is $x" unless ( $x =~ /^\s*$/ );
29         }
30         else {
31             $result = "I can't find the address $dns in DNS";
32         }
33
34     }
35     else {
36
37         &::status("DNS query by name: $dns");
38         $x = join( '.', unpack( 'C4', ( gethostbyname($dns) )[4] ) );
39
40         if ( $x !~ /^\s*$/ ) {
41             $result = "$dns is $x";
42         }
43         else {
44             $result = "I can't find $dns in DNS";
45         }
46     }
47
48     return ($result);
49 }
50
51 sub dns::query {
52     &::performStrictReply( &dns(@_) );
53     return;
54 }
55
56 1;
57
58 # vim:ts=4:sw=4:expandtab:tw=80