From 3ee14638e5a380e3cec2c8a5cb344574c1f6701e Mon Sep 17 00:00:00 2001 From: Leandro Lerena Date: Fri, 3 Jul 2020 09:42:43 +0200 Subject: [PATCH] Fix resolving AF_INET6 --- aj/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aj/utils.py b/aj/utils.py index b6fe93a..fbf6a94 100644 --- a/aj/utils.py +++ b/aj/utils.py @@ -10,6 +10,8 @@ import socket # ----------------------------------------------------------------------------------- + + class Utilities(): ''' @@ -37,21 +39,21 @@ def translate_status(self, status): logger.warning("could not translate status <%s>" % status) return [status, status] - def convert_ip_from_snmp_format(self, address_type, ip_address): if address_type in ('ipv4', 'ipv4z'): return socket.inet_ntoa(ip_address) elif address_type in ('ipv6', 'ipv6z'): - return socket.inet_ntop(AF_INET6, ip_address) + return socket.inet_ntop(socket.AF_INET6, ip_address) elif address_type == 'dns': return ip_address else: - logger.warning('IP conversion not yet supported for type %s, ip %s' % (address_type, ip_address)) + logger.warning('IP conversion not yet supported for type %s, ip %s' % ( + address_type, ip_address)) return 'IP conversion not yet supported for type %s, ip %s' % (address_type, ip_address) - # for Python 3 port, source https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3/46037362#46037362 + def to_bytes(self, bytes_or_str): if isinstance(bytes_or_str, str): value = bytes_or_str.encode() # uses 'utf-8' for encoding