]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/ipinfo.cgi
cce6097ffd8e8f9e9ea5c6dbb5f589215597f0f4
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
26 # enable only the following on debugging purpose
28 #use CGI::Carp 'fatalsToBrowser';
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32 require "${General::swroot}/header.pl";
33 require "${General::swroot}/location-functions.pl";
37 &Header
::showhttpheaders
();
39 &Header
::openpage
($Lang::tr
{'ip info'}, 1, '');
40 &Header
::openbigbox
('100%', 'left');
44 # Hash which contains the whois servers from
45 # the responisible RIR of the continent.
46 my %whois_servers_by_continent = (
47 "AF" => "whois.afrinic.net",
48 "AS" => "whois.apnic.net",
49 "EU" => "whois.ripe.net",
50 "NA" => "whois.arin.net",
51 "SA" => "whois.lacnic.net"
54 # Default whois server if no continent could be determined.
55 my $whois_server = "whois.arin.net";
57 my $addr = CGI
::param
("ip") || "";
59 if (&General
::validip
($addr)) {
60 my $iaddr = inet_aton
($addr);
61 my $hostname = gethostbyaddr($iaddr, AF_INET
);
62 if (!$hostname) { $hostname = $Lang::tr
{'lookup failed'}; }
64 # enumerate location information for IP address...
65 my $db_handle = &Location
::Functions
::init
();
66 my $ccode = &Location
::Functions
::lookup_country_code
($db_handle, $addr);
67 my $network_flag = &Location
::Functions
::address_has_flag
($addr);
69 # Try to get the continent of the country code.
70 my $continent = &Location
::get_continent_code
($db_handle, $ccode);
72 # Check if a whois server for the continent is known.
73 if($whois_servers_by_continent{$continent}) {
75 $whois_server = $whois_servers_by_continent{$continent};
78 my $flag_icon = &Location
::Functions
::get_flag_icon
($ccode);
80 my $sock = new IO
::Socket
::INET
( PeerAddr
=> $whois_server, PeerPort
=> 43, Proto
=> 'tcp');
83 print $sock "$addr\n";
85 $extraquery = $1 if (/ReferralServer: whois:\/\
/(\S+)\s+/);
91 $whois_server = $extraquery;
92 my $sock = new IO
::Socket
::INET
( PeerAddr
=> $whois_server, PeerPort
=> 43, Proto
=> 'tcp');
95 print $sock "$addr\n";
102 @lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
108 @lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
111 &Header
::openbox
('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $hostname . ') : '.$whois_server);
113 # Check if the address has a flag.
116 my $network_flag_name = &Location
::Functions
::get_full_country_name
($network_flag);
119 print "<h3>This address is marked as $network_flag_name.</h3>\n";
124 foreach my $line (@lines) {
125 print &Header
::cleanhtml
($line,"y");
130 &Header
::openbox
('100%', 'left', $Lang::tr
{'invalid ip'});
132 <p style="text-align: center;">
133 $Lang::tr{'invalid ip'}
143 <td align='center'><a href='$ENV{'HTTP_REFERER'}'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td>
150 &Header
::closebigbox
();
152 &Header
::closepage
();