[pm-h] converting IP<->hostname and UID<->username
Paul Archer
tigger at io.com
Tue Mar 28 17:25:40 PST 2006
Interesting stuff there. But if I'm going to call an external program, I
think I'll stick to getent. It's better than host, dig, etc, for IP/hostname
lookups 'cause it uses the kernel resolver which pays attention to
/etc/nsswitch.conf (which means you can get lookups out of local files, nis,
nis+, dns, or ldap, depending on your machine's configuration).
Thanks,
Paul
7:15pm, Alan Jackson wrote:
> On Tue, 28 Mar 2006 16:01:59 -0600 (CST)
> Paul Archer <tigger at io.com> wrote:
>
>> Can anyone suggest modules that can convert IP addresses to and from
>> hostnames, and UIDs to and from usernames? I've searched CPAN, but I
>> didn't come up with anything.
>> Or should I just call 'getent'? (That works for UID<->username, but not for
>> IP addresses not in the host file...)
>>
>
> Not an easy problem. I've written a lot of anti-spam software, and have beaten
> on this problem several times. Here is a snippet of code that does a pretty
> good job...
>
> $host = `/usr/bin/host $ip`;
> my $foo = (split(/\s+/, $host))[4];
> if ($host =~ /not found/ || length($foo)<4) {
> $host = `zcw -h $ip | grep Abuse`;
> }
> if (length $host < 1) {$host = 'UNK';}
> if ($host eq 'reached') {$host = 'UNK';}
> $host = (split(/\s+/,$host))[-1];
> $host = (split(/@/,$host))[-1];
>
> zcw is a nice bit of code I got from www.cyberabuse.org.
>
> Of course, before I even go through these gyrations, I have a simple
> database that I keep every IP address I have received e-mail from,
> the domain, and a counter, and I check that first.
>
>
> --
> -----------------------------------------------------------------------
> | Alan K. Jackson | To see a World in a Grain of Sand |
> | alan at ajackson.org | And a Heaven in a Wild Flower, |
> | www.ajackson.org | Hold Infinity in the palm of your hand |
> | Houston, Texas | And Eternity in an hour. - Blake |
> -----------------------------------------------------------------------
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
>
---------------------------------------------------
Tech Support: "I need you to boot the computer."
Customer: (THUMP! Pause.) "No, that didn't help."
---------(http://www.rinkworks.com/stupid)---------
More information about the Houston
mailing list