Improve geo bypass mechanism
* Introduce geo bypass context * Add ability to bypass based on IP blocks in CIDR notation * Introduce --geo-bypass-ip-block
This commit is contained in:
parent
a93ce61bd5
commit
5f95927a62
11 changed files with 113 additions and 28 deletions
|
@ -3534,10 +3534,13 @@ class GeoUtils(object):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def random_ipv4(cls, code):
|
||||
block = cls._country_ip_map.get(code.upper())
|
||||
if not block:
|
||||
return None
|
||||
def random_ipv4(cls, code_or_block):
|
||||
if len(code_or_block) == 2:
|
||||
block = cls._country_ip_map.get(code_or_block.upper())
|
||||
if not block:
|
||||
return None
|
||||
else:
|
||||
block = code_or_block
|
||||
addr, preflen = block.split('/')
|
||||
addr_min = compat_struct_unpack('!L', socket.inet_aton(addr))[0]
|
||||
addr_max = addr_min | (0xffffffff >> int(preflen))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue