Skip to content

Instantly share code, notes, and snippets.

@fagci
Last active November 23, 2022 17:16
Show Gist options
  • Save fagci/27d151c35bb0010ec7826284001858fe to your computer and use it in GitHub Desktop.
Save fagci/27d151c35bb0010ec7826284001858fe to your computer and use it in GitHub Desktop.
Random public (global) IP v4 addresses generator
from ipaddress import IPv4Address
from random import randrange
def generate_ips(count=20):
while count: # negative values makes infinite generator
ip_address = IPv4Address(randrange(0x01000000, 0xffffffff))
if ip_address.is_global and not ip_address.is_multicast:
count -= 1
yield str(ip_address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment