Skip to content

Instantly share code, notes, and snippets.

@septs
septs / gen-ip.py
Last active August 29, 2024 03:26
Generate Random IP-Port Pair
#!/usr/bin/env python3
import sys
from ipaddress import IPv4Address, IPv4Network
from random import randbytes, randrange
# https://fetch.spec.whatwg.org/#port-blocking
# fmt: off
restricted_ports = {
1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79, 87, 95, 101, 102, 103, 104, 109,
110, 111, 113, 115, 117, 119, 123, 135, 137, 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530,