]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/ipinfo.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 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";
35 # Load colours for current theme...
37 my %mainsettings = ();
38 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
39 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
43 &Header
::showhttpheaders
();
48 # Hash which contains the whois servers from
49 # the responisible RIR of the continent.
50 my %whois_servers_by_continent = (
51 "AF" => "whois.afrinic.net",
52 "AS" => "whois.apnic.net",
53 "EU" => "whois.ripe.net",
54 "NA" => "whois.arin.net",
55 "SA" => "whois.lacnic.net"
58 # Default whois server if no continent could be determined.
59 my $whois_server = "whois.arin.net";
61 my $addr = CGI
::param
("ip") || "";
63 if (&General
::validip
($addr)) {
64 # Write HTML page header...
65 &Header
::openpage
($Lang::tr
{'ip info for'} . ' ' . $addr, 1, '');
66 &Header
::openbigbox
('100%', 'left');
68 my $iaddr = inet_aton
($addr);
69 my $hostname = gethostbyaddr($iaddr, AF_INET
);
70 if (!$hostname) { $hostname = $Lang::tr
{'ptr lookup failed'}; }
72 # Enumerate location information for IP address...
73 my $ccode = &Location
::Functions
::lookup_country_code
($addr);
74 my $cname = &Location
::Functions
::get_full_country_name
($ccode);
75 my @network_flags = &Location
::Functions
::address_has_flags
($addr);
77 # Try to get the continent of the country code.
78 my $continent = &Location
::Functions
::get_continent_code
($ccode);
80 # Enumerate Autonomous System details for IP address...
81 my $asn = &Location
::Functions
::lookup_asn
($addr);
84 $as_name = &Location
::Functions
::get_as_name
($asn);
86 # In case we have found an AS name, make output more readable...
88 $as_name = "- " . $as_name;
92 $asn = $Lang::tr
{'asn lookup failed'};
95 # Check if a whois server for the continent is known.
96 if($whois_servers_by_continent{$continent}) {
98 $whois_server = $whois_servers_by_continent{$continent};
101 my $flag_icon = &Location
::Functions
::get_flag_icon
($ccode);
103 &Header
::openbox
('100%', 'left', $Lang::tr
{'ip basic info'});
107 <table class="tbl" width='100%'>
109 <td bgcolor='$color{'color22'}'><strong>$Lang::tr{'country'}</strong></td>
110 <td bgcolor='$color{'color22'}'>$cname <a href='country.cgi#$ccode'><img src="$flag_icon" border="0" align="absmiddle" alt="$cname" title="$cname" /></td>
113 <td bgcolor='$color{'color20'}'><strong>$Lang::tr{'ptr'}</strong></td>
114 <td bgcolor='$color{'color20'}'>$hostname</td>
117 <td bgcolor='$color{'color22'}'><strong>$Lang::tr{'autonomous system'}</strong></td>
118 <td bgcolor='$color{'color22'}'>$asn $as_name</td>
122 # Check if the address has a flag.
123 if (@network_flags) {
124 # Get amount of flags for this network.
125 my $flags_amount = @network_flags;
128 # Loop through the array of network_flags.
129 foreach my $network_flag (@network_flags) {
130 # Increment value of processed flags.
133 # Get the network flag name.
134 my $network_flag_name = &Location
::Functions
::get_full_country_name
($network_flag);
138 if ($processed_flags % 2) {
139 $col = "bgcolor='$color{'color20'}'"; }
141 $col = "bgcolor='$color{'color22'}'";
147 <td $col><strong>$network_flag_name</strong></td>
148 <td $col>$Lang::tr{'yes'}</td>
155 print " </center>\n";
159 my $sock = new IO
::Socket
::INET
( PeerAddr
=> $whois_server, PeerPort
=> 43, Proto
=> 'tcp');
162 print $sock "$addr\n";
164 $extraquery = $1 if (/ReferralServer: whois:\/\
/(\S+)\s+/);
170 $whois_server = $extraquery;
171 my $sock = new IO
::Socket
::INET
( PeerAddr
=> $whois_server, PeerPort
=> 43, Proto
=> 'tcp');
174 print $sock "$addr\n";
181 @lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
187 @lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
190 &Header
::openbox
('100%', 'left', $Lang::tr
{'whois results from'} . " " . $whois_server);
193 foreach my $line (@lines) {
194 print &Header
::cleanhtml
($line,"y");
199 # Open HTML page header in case of invalid IP addresses
200 &Header
::openpage
($Lang::tr
{'ip info'}, 1, '');
201 &Header
::openbigbox
('100%', 'left');
203 &Header
::openbox
('100%', 'left', $Lang::tr
{'invalid ip'});
205 <p style="text-align: center;">
206 $Lang::tr{'invalid ip'}
216 <td align='center'><a href='$ENV{'HTTP_REFERER'}'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td>
223 &Header
::closebigbox
();
225 &Header
::closepage
();