Created
August 14, 2025 01:37
-
-
Save Pymmdrza/09795e7f5ac082330a4f11419242dd73 to your computer and use it in GitHub Desktop.
IPv4 Generated from range octet
This file contains hidden or 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 random | |
| from typing import Sequence | |
| # Default per-octet inclusive ranges for the generated IPv4 address | |
| OCTET_RANGES: tuple[tuple[int, int], ...] = ( | |
| (31, 245), | |
| (31, 245), | |
| (33, 245), | |
| (66, 245), | |
| ) | |
| def generate_ipv4(ranges: Sequence[tuple[int, int]] = OCTET_RANGES) -> str: | |
| """ | |
| Generate a random IPv4 address using per-octet inclusive ranges. | |
| """ | |
| octets = [random.randint(low, high) for (low, high) in ranges] | |
| return ".".join(map(str, octets)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment