Spam catcher (was Re: Separating IP nodes)

Huaiyu Zhu hzhu at yahoo.com
Tue Sep 5 20:30:30 EDT 2000


On Sun, 03 Sep 2000 23:22:41 -0600, Kevin Breit
<battery841 at remove.for.no.spam.mypad.com> wrote: 
>Hey,
>	In my app, I have a user enter an IP address.  Great.  Now, I want to 
>increment the last number.  For example:
>1.1.1.1 becomes 1.1.1.2 (yes...thats an odd IP)
>What is the best way to separate that and increment only the last number?  
>I'm thinking some sort of regex, but not sure.  


This is not what you are looking for, but it's related, and I thought it
might be useful to others: As I've had received quite a few spams recently
I've written this little program so that I can catch the host of the spammer
and report to their ISP.

Huaiyu

"""
$Id: ip_demangle.py,v 1.1.1.1 2000/09/06 00:30:46 hzhu Exp $

ip_demangle.py: Demangle an ip address written as a single number
Useful for catching spammers hiding behind little tricks.

Use it like:
	python ip_demangle.py 00032100360014

"""

def ip_demangler(ip, show_intermediate=0):
	hexcode = hex(ip)
	ip4 = []
	if show_intermediate: print "hex dec"
	for i in range(4):
		hseg = hexcode[(i+1)*2 : (i+2)*2]
		dseg = str(eval('0x'+hseg))
		if show_intermediate: print " %s % 3s" %(hseg, dseg)
		ip4.append(dseg)
	return ".".join(ip4)
	

if __name__ == "__main__":
	import sys, os
	ips = sys.argv[1:] or ["3627528556"]
	for ip in ips:
		print "original", ip

		ip = eval(ip+"L")
		print "decimal:", ip

		ip =  ip_demangler(ip, 1)
		print "conventional:", ip
		os.system("nslookup " + ip)



More information about the Python-list mailing list