]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | #!/usr/bin/perl\r |
2 | #\r | |
3 | # SmoothWall CGIs\r | |
4 | #\r | |
5 | # This code is distributed under the terms of the GPL\r | |
6 | #\r | |
7 | # (c) The SmoothWall Team\r | |
8 | #\r | |
9 | # (c) 2002 Josh Grubman <jg@false.net> - Multiple registry IP lookup code\r | |
10 | #\r | |
11 | # $Id: ipinfo.cgi,v 1.4.2.3 2005/02/22 22:21:56 gespinasse Exp $\r | |
12 | #\r | |
13 | \r | |
14 | use IO::Socket;\r | |
15 | use strict;\r | |
16 | \r | |
17 | # enable only the following on debugging purpose\r | |
18 | #use warnings;\r | |
19 | #use CGI::Carp 'fatalsToBrowser';\r | |
20 | \r | |
21 | require 'CONFIG_ROOT/general-functions.pl';\r | |
22 | require "${General::swroot}/lang.pl";\r | |
23 | require "${General::swroot}/header.pl";\r | |
24 | \r | |
25 | my %cgiparams=();\r | |
26 | \r | |
27 | &Header::showhttpheaders();\r | |
28 | \r | |
29 | &Header::getcgihash(\%cgiparams);\r | |
30 | \r | |
31 | $ENV{'QUERY_STRING'} =~s/&//g;\r | |
32 | my @addrs = split(/ip=/,$ENV{'QUERY_STRING'});\r | |
33 | \r | |
34 | my %whois_servers = ("RIPE"=>"whois.ripe.net","APNIC"=>"whois.apnic.net","LACNIC"=>"whois.lacnic.net");\r | |
35 | \r | |
36 | &Header::openpage($Lang::tr{'ip info'}, 1, '');\r | |
37 | \r | |
38 | &Header::openbigbox('100%', 'left');\r | |
39 | my @lines=();\r | |
40 | my $extraquery='';\r | |
41 | foreach my $addr (@addrs) {\r | |
42 | next if $addr eq "";\r | |
43 | $extraquery='';\r | |
44 | @lines=();\r | |
45 | my $whoisname = "whois.arin.net";\r | |
46 | my $iaddr = inet_aton($addr);\r | |
47 | my $hostname = gethostbyaddr($iaddr, AF_INET);\r | |
48 | if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; }\r | |
49 | \r | |
50 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');\r | |
51 | if ($sock)\r | |
52 | {\r | |
53 | print $sock "$addr\n";\r | |
54 | while (<$sock>) {\r | |
55 | $extraquery = $1 if (/NetType: Allocated to (\S+)\s+/);\r | |
56 | push(@lines,$_);\r | |
57 | }\r | |
58 | close($sock);\r | |
59 | if ($extraquery) {\r | |
60 | undef (@lines);\r | |
61 | $whoisname = $whois_servers{$extraquery};\r | |
62 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');\r | |
63 | if ($sock)\r | |
64 | {\r | |
65 | print $sock "$addr\n";\r | |
66 | while (<$sock>) {\r | |
67 | push(@lines,$_);\r | |
68 | }\r | |
69 | }\r | |
70 | else\r | |
71 | {\r | |
72 | @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );\r | |
73 | }\r | |
74 | }\r | |
75 | }\r | |
76 | else\r | |
77 | {\r | |
78 | @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );\r | |
79 | }\r | |
80 | \r | |
81 | &Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname);\r | |
82 | print "<pre>\n";\r | |
83 | foreach my $line (@lines) {\r | |
84 | print &Header::cleanhtml($line,"y");\r | |
85 | }\r | |
86 | print "</pre>\n";\r | |
87 | &Header::closebox();\r | |
88 | }\r | |
89 | \r | |
90 | print <<END\r | |
91 | <div align='center'>\r | |
92 | <table width='80%'>\r | |
93 | <tr>\r | |
94 | <td align='center'><a href='$ENV{'HTTP_REFERER'}'>$Lang::tr{'back'}</a></td>\r | |
95 | </tr>\r | |
96 | </table>\r | |
97 | </div>\r | |
98 | END\r | |
99 | ;\r | |
100 | \r | |
101 | &Header::closebigbox();\r | |
102 | \r | |
103 | &Header::closepage();\r |