Revision: 41131
Updated Code
at February 12, 2011 12:55 by magna
Updated Code
import socket, struct
def inet_range(start, stop):
"""Generator to iterate over an interval of IPs.
start & stop should be IPs as string, e.g. '127.0.0.1'.
"""
lstart, = struct.unpack('>L', socket.inet_aton(start))
lstop, = struct.unpack('>L', socket.inet_aton(stop))
inc = 0
while inc <= (lstop - lstart):
lcur = lstart + inc
inc += 1
yield socket.inet_ntoa(struct.pack('>L', lcur))
Revision: 41130
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 12, 2011 12:51 by magna
Initial Code
import socket, struct
def inet_range(start, stop):
"""Generator to iterate over an interval of IPs."""
lstart, = struct.unpack('>L', socket.inet_aton(start))
lstop, = struct.unpack('>L', socket.inet_aton(stop))
inc = 0
while inc <= (lstop - lstart):
lcur = lstart + inc
inc += 1
yield socket.inet_ntoa(struct.pack('>L', lcur))
Initial URL
Initial Description
Initial Title
Generator to iterate over an interval of IPs
Initial Tags
Initial Language
Python