]>
Commit | Line | Data |
---|---|---|
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 | 21 | |
f367d5b3 | 22 | use CGI; |
ac1cfefa MT |
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 | ||
986e08d9 | 30 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
31 | require "${General::swroot}/lang.pl"; |
32 | require "${General::swroot}/header.pl"; | |
9b5a17bf | 33 | require "${General::swroot}/geoip-functions.pl"; |
ac1cfefa MT |
34 | |
35 | my %cgiparams=(); | |
36 | ||
37 | &Header::showhttpheaders(); | |
38 | ||
ac1cfefa | 39 | &Header::openpage($Lang::tr{'ip info'}, 1, ''); |
ac1cfefa MT |
40 | &Header::openbigbox('100%', 'left'); |
41 | my @lines=(); | |
42 | my $extraquery=''; | |
f367d5b3 MT |
43 | |
44 | my $addr = CGI::param("ip") || ""; | |
45 | ||
46 | if (&General::validip($addr)) { | |
ac1cfefa MT |
47 | $extraquery=''; |
48 | @lines=(); | |
49 | my $whoisname = "whois.arin.net"; | |
50 | my $iaddr = inet_aton($addr); | |
51 | my $hostname = gethostbyaddr($iaddr, AF_INET); | |
52 | if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; } | |
53 | ||
9b5a17bf PM |
54 | # enumerate GeoIP information for IP address... |
55 | my $ccode = &GeoIP::lookup($addr); | |
56 | my $flag_icon = &GeoIP::get_flag_icon($ccode); | |
57 | ||
ac1cfefa MT |
58 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp'); |
59 | if ($sock) | |
60 | { | |
8ba55ea6 | 61 | print $sock "n $addr\n"; |
ac1cfefa | 62 | while (<$sock>) { |
8ba55ea6 | 63 | $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/); |
ac1cfefa MT |
64 | push(@lines,$_); |
65 | } | |
66 | close($sock); | |
67 | if ($extraquery) { | |
68 | undef (@lines); | |
8ba55ea6 | 69 | $whoisname = $extraquery; |
ac1cfefa MT |
70 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp'); |
71 | if ($sock) | |
72 | { | |
73 | print $sock "$addr\n"; | |
74 | while (<$sock>) { | |
75 | push(@lines,$_); | |
76 | } | |
77 | } | |
78 | else | |
79 | { | |
80 | @lines = ( "$Lang::tr{'unable to contact'} $whoisname" ); | |
81 | } | |
82 | } | |
83 | } | |
84 | else | |
85 | { | |
86 | @lines = ( "$Lang::tr{'unable to contact'} $whoisname" ); | |
87 | } | |
88 | ||
9b5a17bf | 89 | &Header::openbox('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $hostname . ') : '.$whoisname); |
ac1cfefa MT |
90 | print "<pre>\n"; |
91 | foreach my $line (@lines) { | |
92 | print &Header::cleanhtml($line,"y"); | |
93 | } | |
94 | print "</pre>\n"; | |
95 | &Header::closebox(); | |
f367d5b3 MT |
96 | } else { |
97 | &Header::openbox('100%', 'left', $Lang::tr{'invalid ip'}); | |
98 | print <<EOF; | |
99 | <p style="text-align: center;"> | |
100 | $Lang::tr{'invalid ip'} | |
101 | </p> | |
102 | EOF | |
103 | &Header::closebox(); | |
ac1cfefa MT |
104 | } |
105 | ||
106 | print <<END | |
107 | <div align='center'> | |
108 | <table width='80%'> | |
109 | <tr> | |
415cbcec | 110 | <td align='center'><a href='$ENV{'HTTP_REFERER'}'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td> |
ac1cfefa MT |
111 | </tr> |
112 | </table> | |
113 | </div> | |
114 | END | |
115 | ; | |
116 | ||
117 | &Header::closebigbox(); | |
118 | ||
119 | &Header::closepage(); |