def oid_to_ipv4(oid):
"""Converts a sequence of 4 numbers to an IPv4 object in the fastest
known way.
:param oid: Any list or tuple of 4 integers.
"""
if len(oid) != 4:
raise ValueError("IPv4 address must be 4 octets, not %d" % len(oid))
try:
addr, = unpack("!I", array.array("B", oid).tostring())
except OverflowError as error:
raise ValueError(error)
return IP(addr, ipversion=4)
#############################################################################
# Varios OID consumer functions, which can be fed to the consume() function #
#############################################################################
# pylint: disable=invalid-name
评论列表
文章目录