You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Marc Perkel <ma...@perkel.com> on 2007/07/22 04:44:44 UTC

DNS Perl Help? [ot]

OK - I'm not experienced at Perl by trying to do something that should 
be fairly simple for those of you who are good at it.

I need a subroutine that I can pass and IP address to. It will do a 
reverse DNS lookup and get a hostname. Then lookup the hostname to 
verify that one of the IP addresses it returns matched the IP that was 
looked up. Return the host name if it succeeds ot an empty string if not.

How do you do that?

I'm building what will be an impressive public DNS blacklist/whitelist 
which I will share when it's working.

Thanks in advance.

Oh - also.

If I have a string, what's that fastest way to count the number of 
periods in the string?


Re: DNS Perl Help? [ot]

Posted by Steve Bertrand <ia...@ibctech.ca>.
> OK - Thanks for your help on that one, Still need the DNS stuff figured
> out, That's the last piece in what will be an extrodinarilly powerful
> whitelisting system. I'll publish the code once it is tested. I think a
> lot of people will want to use it and improve it.

Using Net::DNS, here is a snip of what I have used in the past. It
returns the PTR record, and if not available, returns the IP.

sub get_ame {

        my $ip = shift;
        my $res = Net::DNS::Resolver->new;
        my $query = $res->search("$ip");

        if ($query) {
                foreach my $rr ($query->answer) {
                        next unless $rr->type eq "PTR";
                        return ($rr->rdatastr);
                }
        } else {
                return ($ip);
        }

}

HTH,

Steve



Re: DNS Perl Help? [ot]

Posted by Marc Perkel <ma...@perkel.com>.

Theo Van Dinter wrote:
> On Sun, Jul 22, 2007 at 07:15:50AM -0000, hamann.w@t-online.de wrote:
>   
>> Mark Perkel wrote:
>> If I have a string, what's that fastest way to count the number of 
>> periods in the string?
>>
>> in perl, I would probably split the string at the periods
>>
>> @parts = split /\./, $string;
>> and then just use the number of splits
>> $#parts
>>     
>
> I believe the official/fastest/shortest method is:
>
> $count = $string =~ y/.//;
>
>   

OK - Thanks for your help on that one, Still need the DNS stuff figured 
out, That's the last piece in what will be an extrodinarilly powerful 
whitelisting system. I'll publish the code once it is tested. I think a 
lot of people will want to use it and improve it.


Re: DNS Perl Help? [ot]

Posted by Theo Van Dinter <fe...@apache.org>.
On Sun, Jul 22, 2007 at 07:15:50AM -0000, hamann.w@t-online.de wrote:
> Mark Perkel wrote:
> If I have a string, what's that fastest way to count the number of 
> periods in the string?
> 
> in perl, I would probably split the string at the periods
> 
> @parts = split /\./, $string;
> and then just use the number of splits
> $#parts

I believe the official/fastest/shortest method is:

$count = $string =~ y/.//;

-- 
Randomly Selected Tagline:
If a can of Alpo costs 38 cents, would it cost $2.50 in Dog Dollars?