[common] support multiple codes/blocks for '--xff'

for example '--xff JP,CN,105.48.0.0/12'
This commit is contained in:
Mike Fährmann
2026-02-04 20:58:59 +01:00
parent 947085c6e3
commit 3d36ee0e53
4 changed files with 27 additions and 15 deletions

View File

@@ -258,12 +258,21 @@ COUNTRY_IP_MAP = {
}
def random_ipv4(block):
if len(block) == 2:
block = COUNTRY_IP_MAP.get(block.upper())
if not block:
return None
def random_ipv4(blocks):
if isinstance(blocks, str):
blocks = blocks.split(",")
cidr = []
for block in blocks:
if len(block) == 2:
block = COUNTRY_IP_MAP.get(block.upper())
if not block:
continue
cidr.append(block)
if not cidr:
return None
block = random.choice(cidr)
addr, _, preflen = block.partition("/")
if not preflen:
return addr

View File

@@ -494,8 +494,8 @@ def build_parser():
"--xff",
dest="geo-bypass", metavar="VALUE", action=ConfigAction,
help=("Use a fake 'X-Forwarded-For' HTTP header to try bypassing "
"geographic restrictions. Can be an IP block in CIDR notation "
"or a two-letter ISO 3166-2 country code")
"geographic restrictions. Can be IP blocks in CIDR notation "
"or two-letter ISO 3166-2 country codes (12.0.0.0/8,FR,CN)")
)
networking.add_argument(
"--source-address",