rbl interface in python (spamming)?

Paul Wright -$Paul$- at verence.demon.co.uk
Wed Nov 15 14:15:49 EST 2000


In article <8upo9e$jrp$1 at nnrp1.deja.com>,  <pereran at my-deja.com> wrote:
>Looking for a python module that talks to RBL

The RBL just uses a DNS zone. To look see if IP address a.b.c.d is in
the RBL, look up d.c.b.a.rbl.maps.vix.com. If it exists, that host is in
the RBL. You can do DNS lookups using the gethostbyname function in the
socket module. Here's an example:

import string
import socket

def is_in_rbl (ip, rbl_domain = "rbl.maps.vix.com"):
    
    l = string.split (ip, ".")
    l.reverse ()
    lookup_host = string.join (l, ".") + "." + rbl_domain
    try:
        addr = socket.gethostbyname (lookup_host)
    except socket.error:
        addr = ''

    # Some RBL-like lists use the returned addr to signify something,
    # so we'll return it.
    return addr 
      
if __name__ == "__main__":
    if is_in_rbl ("127.0.0.2"):
        print "127.0.0.2 is in the RBL."

    if is_in_rbl ("127.0.0.2", "relays.orbs.org"):
        print "127.0.0.2 is in the ORBS."
# Cut here

What I think would be really cool is an automated spam reporting helper
using Python. There's one in Perl but I can't help thinking Python would
be easier to extend, and to add a GUI too and so on. Maybe I'll write
one.

-- 
----- Paul Wright ------| 12. The Enterprise visits an earth-type planet
-paul.wright at pobox.com--| called "Paradise" where everyone is happy all of
http://pobox.com/~pw201 | the time. However, everything is soon revealed to
                        | be exactly what it seems.



More information about the Python-list mailing list