Fwd: [Tutor] Create list of IPs
Liam Clarke
cyresse at gmail.com
Sun Feb 20 11:43:07 CET 2005
Erp.
---------- Forwarded message ----------
From: Liam Clarke <cyresse at gmail.com>
Date: Sun, 20 Feb 2005 23:42:43 +1300
Subject: Re: [Tutor] Create list of IPs
To: Ralfas Jegorovas <ralfasy2k at hotmail.com>
Hi, you could save yourself some hassle and do
>>> minipstr = '1.0.0.1'
>>> maxipstr = '1.0.15.16'
>>>
>>> minip = map(int, minipstr.split('.'))
>>> maxip = map(int, maxipstr.split('.'))
>>>
>>> iplist = []
>>>
>>> for a in range(minip[2], maxip[2]+1):
... if a < maxip[2]:
... for b in range(minip[3], 255):
... iplist.append('.'.join(map(str,
[minip[0],minip[1], a, b])))
... else:
... for b in range(minip[3], minip[3]+1):
... iplist.append('.'.join(map(str,
[minip[0],minip[1], a, b])))
Eek, that's a bit Perlish, might want to break the iplist.append line into
ipintlist = [minip[0],minip[1], a, b]
ipstrlist = map(str, ipintlist)
iplist.append('.'.join(ipstrlist))
HTH
Liam Clarke
<Disclaimer>
It's ugly, but it works, someone better will shortly post a prettier,
more elegant and efficient version.
</disclaimer>
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
More information about the Tutor
mailing list