]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/ipinfo.cgi
Merge remote-tracking branch 'origin/master' into next
[ipfire-2.x.git] / html / cgi-bin / ipinfo.cgi
CommitLineData
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
MT
21
22use IO::Socket;
23use strict;
24
25# enable only the following on debugging purpose
26#use warnings;
27#use CGI::Carp 'fatalsToBrowser';
28
986e08d9 29require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
30require "${General::swroot}/lang.pl";
31require "${General::swroot}/header.pl";
32
33my %cgiparams=();
34
35&Header::showhttpheaders();
36
37&Header::getcgihash(\%cgiparams);
38
39$ENV{'QUERY_STRING'} =~s/&//g;
40my @addrs = split(/ip=/,$ENV{'QUERY_STRING'});
41
ac1cfefa
MT
42&Header::openpage($Lang::tr{'ip info'}, 1, '');
43
44&Header::openbigbox('100%', 'left');
45my @lines=();
46my $extraquery='';
47foreach my $addr (@addrs) {
48next if $addr eq "";
49 $extraquery='';
50 @lines=();
51 my $whoisname = "whois.arin.net";
52 my $iaddr = inet_aton($addr);
53 my $hostname = gethostbyaddr($iaddr, AF_INET);
54 if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; }
55
56 my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
57 if ($sock)
58 {
8ba55ea6 59 print $sock "n $addr\n";
ac1cfefa 60 while (<$sock>) {
8ba55ea6 61 $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
ac1cfefa
MT
62 push(@lines,$_);
63 }
64 close($sock);
65 if ($extraquery) {
66 undef (@lines);
8ba55ea6 67 $whoisname = $extraquery;
ac1cfefa
MT
68 my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
69 if ($sock)
70 {
71 print $sock "$addr\n";
72 while (<$sock>) {
73 push(@lines,$_);
74 }
75 }
76 else
77 {
78 @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
79 }
80 }
81 }
82 else
83 {
84 @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
85 }
86
87 &Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname);
88 print "<pre>\n";
89 foreach my $line (@lines) {
90 print &Header::cleanhtml($line,"y");
91 }
92 print "</pre>\n";
93 &Header::closebox();
94}
95
96print <<END
97<div align='center'>
98<table width='80%'>
99<tr>
100 <td align='center'><a href='$ENV{'HTTP_REFERER'}'>$Lang::tr{'back'}</a></td>
101</tr>
102</table>
103</div>
104END
105;
106
107&Header::closebigbox();
108
109&Header::closepage();