]>
Commit | Line | Data |
---|---|---|
ac1cfefa | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
8ba55ea6 | 5 | # Copyright (C) 2010 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
ac1cfefa | 21 | |
f367d5b3 | 22 | use CGI; |
ac1cfefa MT |
23 | use IO::Socket; |
24 | use strict; | |
25 | ||
26 | # enable only the following on debugging purpose | |
27 | #use warnings; | |
28 | #use CGI::Carp 'fatalsToBrowser'; | |
29 | ||
986e08d9 | 30 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
31 | require "${General::swroot}/lang.pl"; |
32 | require "${General::swroot}/header.pl"; | |
33 | ||
34 | my %cgiparams=(); | |
35 | ||
36 | &Header::showhttpheaders(); | |
37 | ||
ac1cfefa | 38 | &Header::openpage($Lang::tr{'ip info'}, 1, ''); |
ac1cfefa MT |
39 | &Header::openbigbox('100%', 'left'); |
40 | my @lines=(); | |
41 | my $extraquery=''; | |
f367d5b3 MT |
42 | |
43 | my $addr = CGI::param("ip") || ""; | |
44 | ||
45 | if (&General::validip($addr)) { | |
ac1cfefa MT |
46 | $extraquery=''; |
47 | @lines=(); | |
48 | my $whoisname = "whois.arin.net"; | |
49 | my $iaddr = inet_aton($addr); | |
50 | my $hostname = gethostbyaddr($iaddr, AF_INET); | |
51 | if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; } | |
52 | ||
53 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp'); | |
54 | if ($sock) | |
55 | { | |
8ba55ea6 | 56 | print $sock "n $addr\n"; |
ac1cfefa | 57 | while (<$sock>) { |
8ba55ea6 | 58 | $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/); |
ac1cfefa MT |
59 | push(@lines,$_); |
60 | } | |
61 | close($sock); | |
62 | if ($extraquery) { | |
63 | undef (@lines); | |
8ba55ea6 | 64 | $whoisname = $extraquery; |
ac1cfefa MT |
65 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp'); |
66 | if ($sock) | |
67 | { | |
68 | print $sock "$addr\n"; | |
69 | while (<$sock>) { | |
70 | push(@lines,$_); | |
71 | } | |
72 | } | |
73 | else | |
74 | { | |
75 | @lines = ( "$Lang::tr{'unable to contact'} $whoisname" ); | |
76 | } | |
77 | } | |
78 | } | |
79 | else | |
80 | { | |
81 | @lines = ( "$Lang::tr{'unable to contact'} $whoisname" ); | |
82 | } | |
83 | ||
84 | &Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname); | |
85 | print "<pre>\n"; | |
86 | foreach my $line (@lines) { | |
87 | print &Header::cleanhtml($line,"y"); | |
88 | } | |
89 | print "</pre>\n"; | |
90 | &Header::closebox(); | |
f367d5b3 MT |
91 | } else { |
92 | &Header::openbox('100%', 'left', $Lang::tr{'invalid ip'}); | |
93 | print <<EOF; | |
94 | <p style="text-align: center;"> | |
95 | $Lang::tr{'invalid ip'} | |
96 | </p> | |
97 | EOF | |
98 | &Header::closebox(); | |
ac1cfefa MT |
99 | } |
100 | ||
101 | print <<END | |
102 | <div align='center'> | |
103 | <table width='80%'> | |
104 | <tr> | |
105 | <td align='center'><a href='$ENV{'HTTP_REFERER'}'>$Lang::tr{'back'}</a></td> | |
106 | </tr> | |
107 | </table> | |
108 | </div> | |
109 | END | |
110 | ; | |
111 | ||
112 | &Header::closebigbox(); | |
113 | ||
114 | &Header::closepage(); |