timeoutsocket module help

jepler at unpythonic.net jepler at unpythonic.net
Wed Sep 18 04:37:29 CEST 2002


You won't have a lot of luck using timeoutsocket to influence the timeout
of name lookups -- those are done in C code, not at the level where
timeoutsocket can be useful.

Investigate a pure python DNS setup, like pydns
(http://pydns.sourceforge.net/).

Jeff
PS following for your enjoyment, an inefficient program that attempts to
look up a host in many different RBLs, using threads for parallelism and
the aforementioned pydns for lookups with a defined timeout:

RBL_LIST = (
    'bl.redhatgate.com', 'blackholes.intersil.net', 'dews.qmail.org',
    'dssl.imrss.org', 'mr-out.imrss.org', '3y.spam.mrs.kithrup.com',
    'blackhole.com', 'pu.net', 'blackholes.2mbit.com',
    'blackholes.five-ten-sg.com', 'blackholes.mail-abuse.org',
    'blackholes.wirehub.net', 'blacklist.spambag.org',
    'block.blars.org', 'blocktest.relays.osirusoft.com', 'dev.null.dk',
    'dialup.blacklist.jippg.org', 'dialups.mail-abuse.org',
    'dialups.relays.osirusoft.com', 'dnsbl.njabl.org', 'list.dsbl.org',
    'multihop.dsbl.org', 'unconfirmed.dsbl.org', 'dul.maps.vix.com',
    'dul.orca.bc.ca', 'dynablock.wirehub.net', 'flowgoaway.com',
    'formmail.relays.monkeys.com', 'http.opm.blitzed.org',
    'inputs.relays.osirusoft.com', 'ipwhois.rfc-ignorant.org',
    'opm.blitzed.org', 'orbs.dorkslayers.com', 'outputs.orbz.org',
    'relays.ordb.org', 'pm0-no-more.com', 'pu.net',
    'proxies.relays.monkeys.com', 'rbl-plus.mail-abuse.org',
    'rbl.maps.vix.com', 'rbl.spam.org.tr', 'relays.dorkslayers.com',
    'relays.mail-abuse.org', 'relays.osirusoft.com',
    'relays.radparker.com', 'relays.visi.com',
    'sbl.spamhaus.org', 'socks.opm.blitzed.org',
    'socks.relays.osirusoft.com', 'bl.spamcop.net',
    'spamguard.leadmon.net', 'spamhaus.relays.osirusoft.com',
    'spammers.v6net.org', 'spamsites.relays.osirusoft.com',
    'spamsources.fabel.dkspews.relays.osirusoft.com',
    'wingate.opm.blitzed.org', 'xbl.selwerd.cx', 'ztl.dorkslayers.com',
    'or.orbl.org', 'spamips.rbl.shub-inter.net',
)

import sys, socket, threading, DNS

DNS.DiscoverNameServers()

def check_one(i, j):
    dns = DNS.Request(timeout=5)
    k = "%s.%s" % (i, j)
    try:
	res = dns.req(k)
    except DNS.DNSError, reason:
	l = reason
    else:
	status = res.header['status']
	if status == 'NOERROR' and res.answers:
	    l = res.answers[0]['data']
	elif status == 'NOERROR':
	    l = "NOERROR but no answer?"
	elif status == 'NXDOMAIN':
	    return
	else:
	    l = status
    print "%-50s %s" % (k, l)
	
for i in sys.argv[1:]:
    i = socket.gethostbyname(i).split(".")
    i.reverse()
    i = ".".join(i)
    tl = []
    for j in RBL_LIST:
	t = threading.Thread(target=check_one, args=(i, j))
	t.start()
	tl.append(t)

    while tl:
	tl.pop().join()





More information about the Python-list mailing list