[pm-h] converting IP<->hostname and UID<->username

Alan Jackson alan at ajackson.org
Tue Mar 28 17:15:02 PST 2006


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       |
-----------------------------------------------------------------------


More information about the Houston mailing list