[common] support multiple codes/blocks for '--xff'
for example '--xff JP,CN,105.48.0.0/12'
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user