/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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))
Comments
