]>
Commit | Line | Data |
---|---|---|
ac1cfefa | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
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 | |
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 | ||
986e08d9 | 29 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
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 | my %whois_servers = ("RIPE"=>"whois.ripe.net","APNIC"=>"whois.apnic.net","LACNIC"=>"whois.lacnic.net"); | |
43 | ||
44 | &Header::openpage($Lang::tr{'ip info'}, 1, ''); | |
45 | ||
46 | &Header::openbigbox('100%', 'left'); | |
47 | my @lines=(); | |
48 | my $extraquery=''; | |
49 | foreach my $addr (@addrs) { | |
50 | next if $addr eq ""; | |
51 | $extraquery=''; | |
52 | @lines=(); | |
53 | my $whoisname = "whois.arin.net"; | |
54 | my $iaddr = inet_aton($addr); | |
55 | my $hostname = gethostbyaddr($iaddr, AF_INET); | |
56 | if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; } | |
57 | ||
58 | my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp'); | |
59 | if ($sock) | |
60 | { | |
61 | print $sock "$addr\n"; | |
62 | while (<$sock>) { | |
63 | $extraquery = $1 if (/NetType: Allocated to (\S+)\s+/); | |
64 | push(@lines,$_); | |
65 | } | |
66 | close($sock); | |
67 | if ($extraquery) { | |
68 | undef (@lines); | |
69 | $whoisname = $whois_servers{$extraquery}; | |
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 | ||
89 | &Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname); | |
90 | print "<pre>\n"; | |
91 | foreach my $line (@lines) { | |
92 | print &Header::cleanhtml($line,"y"); | |
93 | } | |
94 | print "</pre>\n"; | |
95 | &Header::closebox(); | |
96 | } | |
97 | ||
98 | print <<END | |
99 | <div align='center'> | |
100 | <table width='80%'> | |
101 | <tr> | |
102 | <td align='center'><a href='$ENV{'HTTP_REFERER'}'>$Lang::tr{'back'}</a></td> | |
103 | </tr> | |
104 | </table> | |
105 | </div> | |
106 | END | |
107 | ; | |
108 | ||
109 | &Header::closebigbox(); | |
110 | ||
111 | &Header::closepage(); |