]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/ipinfo.cgi
Merge branch 'core110'
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / ipinfo.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 IPFire Team <info@ipfire.org> #
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 ###############################################################################
21
22 use CGI;
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
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32 require "${General::swroot}/header.pl";
33
34 my %cgiparams=();
35
36 &Header::showhttpheaders();
37
38 &Header::openpage($Lang::tr{'ip info'}, 1, '');
39 &Header::openbigbox('100%', 'left');
40 my @lines=();
41 my $extraquery='';
42
43 my $addr = CGI::param("ip") || "";
44
45 if (&General::validip($addr)) {
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 {
56 print $sock "n $addr\n";
57 while (<$sock>) {
58 $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
59 push(@lines,$_);
60 }
61 close($sock);
62 if ($extraquery) {
63 undef (@lines);
64 $whoisname = $extraquery;
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();
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();
99 }
100
101 print <<END
102 <div align='center'>
103 <table width='80%'>
104 <tr>
105 <td align='center'><a href='$ENV{'HTTP_REFERER'}'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td>
106 </tr>
107 </table>
108 </div>
109 END
110 ;
111
112 &Header::closebigbox();
113
114 &Header::closepage();