I am a newbie to mp development stack.
After one day of work, I have made a simple handler, which returns the
client's address and its PTR record.
The demo:
https://myhostnames.com/
The code shown below:
package MyHostname;
use strict;
use Net::DNS;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Connection ();
use APR::Table ();
use Apache2::Const -compile => qw(OK FORBIDDEN);
sub handler {
my $r = shift;
my $ip = $r->headers_in->{'CF-Connecting-IP'} ||
$r->connection->client_ip;
my $host = dns_query($ip) || "";
$r->content_type('text/plain; charset=utf-8');
$r->print("Your IP: $ip, Hostname: $host");
return Apache2::Const::OK;
}
sub dns_query {
my $ip = shift;
my $resolver = Net::DNS::Resolver->new();
my $reply = $resolver->query($ip, 'PTR');
if ($reply) {
for my $rr ($reply->answer) {
return $rr->rdstring; # we need only one
}
}
return;
}
1;
Can anyone give your review? Thanks in advance.
Matthias
On Tue, Dec 22, 2020 at 1:49 PM Matthias Peng <[email protected]>
wrote:
> Hello
>
> I am developing a simple mp2 application.
> I looked for the installation for mp2 utils, and found this two:
>
> libapache2-mod-perl2
>
> libapache2-mod-apreq2
>
>
> what're their relations? Should I install both, or only the first one?
>
>
> Thanks.
>