OK, following up on
Arthur's post in which he sketched out how one might do a razor-check on an email message with Python (instead of the standard
Razor package, I've made some progress on another one of the parts of Vipul's Razor.
Essentially, the client part of Vipul's Razor comprises three parts:
razor-check: This is the part Arthur worked on, which simply checks whether an individual email message has been reported as spam.
razor-report: This part reports a message that is not already in the database. This part I have not (yet?) worked on.
razor-discover: This part goes out and "discovers" razor servers, and determines which one is closest (by timing pings to the servers).
Here is my Python code which is essentially equivalent to the razor-discover package available from the links above. It would have to be set up with a cron job (which I don't much know how to do...well, OK, I haven't tried yet). Anyhow, FWIW, here is my Python code:
Code:
import socket, string, os
subdomainlist = list(string.ascii_lowercase)
zone = 'razor.vipul.net'
host_IP_list =[]
response_times = {}
for subd in subdomainlist:
host = '%s.%s' % (subd, zone)
try:
IPaddy = socket.gethostbyname(host)
host_IP_list.append(IPaddy)
except socket.error, e:
pipe = os.popen('dnsquery -t CNAME %s' % host)
data = pipe.read()
if data.find('list.terminator') > -1:
break
for IPaddy in host_IP_list:
pipe = os.popen('ping -n -c 4 %s' % IPaddy)
result_list = pipe.read().split('/')
avg_resp_time = float(result_list[-2])
response_times[avg_resp_time] = IPaddy
time_list = response_times.keys()
time_list.sort()
sorted_host_list = []
for t in time_list:
sorted_host_list.append(response_times[t])
homedir = os.getenv('HOME', '')
f = open(os.path.join(homedir,'.razor.lst'), 'w')
for IPaddy in sorted_host_list:
f.write("%s\n" % IPaddy)
f.close()
The main problem that I find, right now, is that I can only discover two servers. That sure isn't very many!!! I think that Arthur's suggestion, that FutureQuest set up a Razor server right here, on one of their servers, is an excellent idea. Hmm...
One of the two servers is about 40 ms ping away, and the other is more like 116 ms ping away.
Anyhow, this all looks promising. Reading the Perl code and trying to figure out what they are doing is a little tough for me (since I am not JAPH). I cannot see at all how Arthur decided that the correct telnet command to give to the razor server for the razor-check was:
Code:
telnet.write ('key:%s&action:lookup\n.\n' % key)
even though I've looked over the Perl code from which he adapted it several times.
Which kind of stumps me, then, when I try to see how to adapt the razor-report module.
Ah, well. Enough coding for one day, probably, anyways.
<edited code...removed a "raise" statement after the "break" in the exception block>