]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ipinfo.cgi
fbf652244f4091b3e5c27f2a93dbce9db221f02a
[ipfire-2.x.git] / html / cgi-bin / ipinfo.cgi
1 #!/usr/bin/perl
2 #
3 # SmoothWall CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The SmoothWall Team
8 #
9 # (c) 2002 Josh Grubman <jg@false.net> - Multiple registry IP lookup code
10 #
11 # $Id: ipinfo.cgi,v 1.4.2.3 2005/02/22 22:21:56 gespinasse Exp $
12 #
13
14 use IO::Socket;
15 use strict;
16
17 # enable only the following on debugging purpose
18 #use warnings;
19 #use CGI::Carp 'fatalsToBrowser';
20
21 require '/var/ipfire/general-functions.pl';
22 require "${General::swroot}/lang.pl";
23 require "${General::swroot}/header.pl";
24
25 my %cgiparams=();
26
27 &Header::showhttpheaders();
28
29 &Header::getcgihash(\%cgiparams);
30
31 $ENV{'QUERY_STRING'} =~s/&//g;
32 my @addrs = split(/ip=/,$ENV{'QUERY_STRING'});
33
34 my %whois_servers = ("RIPE"=>"whois.ripe.net","APNIC"=>"whois.apnic.net","LACNIC"=>"whois.lacnic.net");
35
36 &Header::openpage($Lang::tr{'ip info'}, 1, '');
37
38 &Header::openbigbox('100%', 'left');
39 my @lines=();
40 my $extraquery='';
41 foreach my $addr (@addrs) {
42 next if $addr eq "";
43 $extraquery='';
44 @lines=();
45 my $whoisname = "whois.arin.net";
46 my $iaddr = inet_aton($addr);
47 my $hostname = gethostbyaddr($iaddr, AF_INET);
48 if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; }
49
50 my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
51 if ($sock)
52 {
53 print $sock "$addr\n";
54 while (<$sock>) {
55 $extraquery = $1 if (/NetType: Allocated to (\S+)\s+/);
56 push(@lines,$_);
57 }
58 close($sock);
59 if ($extraquery) {
60 undef (@lines);
61 $whoisname = $whois_servers{$extraquery};
62 my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
63 if ($sock)
64 {
65 print $sock "$addr\n";
66 while (<$sock>) {
67 push(@lines,$_);
68 }
69 }
70 else
71 {
72 @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
73 }
74 }
75 }
76 else
77 {
78 @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
79 }
80
81 &Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname);
82 print "<pre>\n";
83 foreach my $line (@lines) {
84 print &Header::cleanhtml($line,"y");
85 }
86 print "</pre>\n";
87 &Header::closebox();
88 }
89
90 print <<END
91 <div align='center'>
92 <table width='80%'>
93 <tr>
94 <td align='center'><a href='$ENV{'HTTP_REFERER'}'>$Lang::tr{'back'}</a></td>
95 </tr>
96 </table>
97 </div>
98 END
99 ;
100
101 &Header::closebigbox();
102
103 &Header::closepage();