Created
March 6, 2018 01:26
-
-
Save kot-behemoth/74a8c3304a3834ae61085d867f55f980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
from ipaddress import ip_address | |
all_ips_tuples = itertools.product(range(256), repeat=4) | |
# these are generators, meaning they don't store all values in memory | |
ip_strings = ('.'.join(map(str, ip_tuple)) | |
for ip_tuple in all_ips_tuples) | |
ip_objects = (ip_address(ip_string) | |
for ip_string in ip_strings) | |
# get an IP object | |
next(ip_objects) | |
# get all IP objects - warning, consumes a lot of memory | |
all_ip_objects = list(ip_objects) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples