Python.org, Website of Satan

Michael Hoffman cam.ac.uk at mh391.invalid
Fri Jan 14 12:16:59 CET 2005


Peter Renzland wrote:
> What is the simplest/fastest Python program to determine how many
> IP addresses sum up to 666?
> 
> The simplest/fastest enumerator?
> 
> The simplest/fastest that determines which ones of them are home pages?

This seems to work although it could be made more efficient or elegant. 
Also, the failed gethostbyaddr() calls take forever.

from socket import gethostbyaddr, herror

for a in xrange(256):
     if a < 666-255*3:
         continue
     for b in xrange(256):
         if a+b < 666-255*2:
             continue
         for c in xrange(256):
             if a+b+c < 666-255:
                 continue
             for d in xrange(256):
                 if a + b + c + d == 666:
                     ip_address = "%d.%d.%d.%d" % (a, b, c, d)
                     try:
                         hostname, aliaslist, ipaddrlist = 
gethostbyaddr(ip_address)
                     except herror:
                         hostname = "NONE"
                     print hostname, ip_address
                     break
-- 
Michael Hoffman



More information about the Python-list mailing list