Collecting IP range
Emile van Sebille
emile at fenx.com
Mon Jan 30 21:33:43 EST 2006
"yawgmoth7" <yawgmoth7 at gmail.com> wrote in message
news:cef393a0601301710g1d508568gcafa30ffb2e91091 at mail.gmail.com...
> for ips in range(startip,endip):
> <do blah>
>
Here's one way:
def iterIPs(startip,endip):
import socket, struct
sip = struct.unpack('>L',socket.inet_aton(startip))[0]
eip = struct.unpack('>L',socket.inet_aton(endip))[0]
while sip <= eip:
yield socket.inet_ntoa(struct.pack('>L',sip))
sip += 1
for ii in iterIPs ('1.2.3.0','1.2.3.127'): ii
Emile
More information about the Python-list
mailing list