How do I iterate through a range of IP addresses provided by the user?
I’m flexible on the format, provided it allows all ranges to be specified. Perhaps something like the nmap-style:
'192.0.2.1' # one IP address
'192.0.2.0-31' # one block with 32 IP addresses.
'192.0.2-3.1-254' # two blocks with 254 IP addresses.
'0-255.0-255.0-255.0-255' # the whole IPv4 address space
For example, if the user entered 192.0.2-3.1-254, I would like to know how to generate a list of all the valid IP addresses in this range so that I could iterate through them.
For example: