Skip to content

Commit

Permalink
Fix resolving AF_INET6
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrolerena committed Jul 3, 2020
1 parent de492ed commit 3ee1463
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions aj/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import socket

# -----------------------------------------------------------------------------------


class Utilities():

'''
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3ee1463

Please sign in to comment.