Do ord() on first two bytes of host in checkIPv6Address()

only in python2
This commit is contained in:
Dmitri Bogomolov 2021-07-27 00:51:22 +03:00
parent c11186e7be
commit 06643bbbf3
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -202,15 +202,19 @@ def checkIPv6Address(host, hostStandardFormat, private=False):
Returns hostStandardFormat if it is an IPv6 address, Returns hostStandardFormat if it is an IPv6 address,
otherwise returns False otherwise returns False
""" """
if host == (b'\x00' * 15) + b'\x01': if host == b'\x00' * 15 + b'\x01':
if not private: if not private:
logger.debug('Ignoring loopback address: %s', hostStandardFormat) logger.debug('Ignoring loopback address: %s', hostStandardFormat)
return False return False
if host[0] == b'\xFE' and (ord(host[1]) & 0xc0) == 0x80: try:
host = [ord(c) for c in host[:2]]
except TypeError: # python3 has ints already
pass
if host[0] == 0xfe and host[1] & 0xc0 == 0x80:
if not private: if not private:
logger.debug('Ignoring local address: %s', hostStandardFormat) logger.debug('Ignoring local address: %s', hostStandardFormat)
return hostStandardFormat if private else False return hostStandardFormat if private else False
if (ord(host[0]) & 0xfe) == 0xfc: if host[0] & 0xfe == 0xfc:
if not private: if not private:
logger.debug( logger.debug(
'Ignoring unique local address: %s', hostStandardFormat) 'Ignoring unique local address: %s', hostStandardFormat)