- if ip_version == "ip4":
- ip_addr = binascii.hexlify(inet_aton(ip_addr))
- elif ip_version == "ip6":
- ip_addr = binascii.hexlify(inet_pton(AF_INET6, ip_addr))
+ if ip_version == "ip4" or ip_version == "ip6":
+ ip_addr = binascii.hexlify(ip_address(unicode(ip_addr)).packed)