]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/ipinfo.cgi
ipinfo.cgi: Fix for new arin whois protocol.
[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 IO::Socket;
23 use strict;
24
25 # enable only the following on debugging purpose
26 #use warnings;
27 #use CGI::Carp 'fatalsToBrowser';
28
29 require '/var/ipfire/general-functions.pl';
30 require "${General::swroot}/lang.pl";
31 require "${General::swroot}/header.pl";
32
33 my %cgiparams=();
34
35 &Header::showhttpheaders();
36
37 &Header::getcgihash(\%cgiparams);
38
39 $ENV{'QUERY_STRING'} =~s/&//g;
40 my @addrs = split(/ip=/,$ENV{'QUERY_STRING'});
41
42 &Header::openpage($Lang::tr{'ip info'}, 1, '');
43
44 &Header::openbigbox('100%', 'left');
45 my @lines=();
46 my $extraquery='';
47 foreach my $addr (@addrs) {
48 next 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 {
59 print $sock "n $addr\n";
60 while (<$sock>) {
61 $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
62 push(@lines,$_);
63 }
64 close($sock);
65 if ($extraquery) {
66 undef (@lines);
67 $whoisname = $extraquery;
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
96 print <<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>
104 END
105 ;
106
107 &Header::closebigbox();
108
109 &Header::closepage();