On Fri, 2005-09-16 at 15:19 -0400, Ed Hotchkiss wrote: > This script should just be writing every possibly IP (yea, there are > billions i know blah blah) to a txt file. Instead of just writing the > IP, it continues and the number goes past 4 groups. IE: The possible > IP keeps getting 3 characters longer every time. And at the end of the > last loops do I somehow have to set my mySet to NULL? Any ideas > here?
(SNIP)
> def findIPs():
> for num in range(256):
> mySet = "%03.d" % num
> for num in range(256):
> mySet = mySet + "." + "%03.d" % num
> for num in range(256):
> mySet = mySet + "." + "%03.d" % num
> for num in range(256):
> mySet = mySet + "." + "%03.d" % num
> ipFile.write(mySet+"\n")
>
> findIPs()
>
> ipFile.close()
>
You should be using different variables in that algorithm, because you
are concatenating strings to "mySET" over and over again.
A more efficient approach would be something like:
def findIPs():
ip = 0
while ip < 256**4:
print '.'.join('%03d' % (int(ip >> foo*8) & 255)\
for foo in range(3, -1, -1))
ip += 1
--
Gustavo Picon (http://tabo.aurealsys.com/)
Aureal Systems S.A.C. (http://www.aureal.com.pe/)
[EMAIL PROTECTED]
Tlf: 243-0131
Nextel: 9824*4625
signature.asc
Description: This is a digitally signed message part
-- http://mail.python.org/mailman/listinfo/python-list
