Re: Confused about two development utils

Mithun Bhattacharya <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <CAHTPV9JP_xJqV=0rX3wSQPVEEC8Rnh0K=HgB8zb+xc=3Wzhn8A@mail.gmail.com>
Replying to the DL.

On Tue, Dec 22, 2020 at 7:07 PM Mithun Bhattacharya <[email protected]>
wrote:

> $r->connection->client_ip would report your proxy server if you have a
> reverse proxy setup - this is not a common use case though.
>
> DNS lookup would usually be an expensive process and you are supposed to
> be nice to other services so cache it for the TTL of the PTR record.
>
> On Tue, Dec 22, 2020 at 6:44 PM Matthias Peng <[email protected]>
> wrote:
>
>> 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.
>>>
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.