From: Michael Orlitzky Date: Thu, 22 Sep 2022 01:25:59 +0000 (-0400) Subject: djbdns/common.py: assume IPv6 if an address isn't IPv4. X-Git-Tag: 0.0.1~10 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;ds=inline;h=d9f3e6ef07662990538a9a6fb46f8120ffc37ee5;hp=c965f2fea1788a7faba2c67a4f05c27d5c34373b;p=djbdns-logparse.git djbdns/common.py: assume IPv6 if an address isn't IPv4. In other words, probably crash if convert_ip() is fed garbage. That's OK. We could check the length of the hex string and raise a ValueError if it isn't 8 or 32, but we might be solving problems that don't exist. --- diff --git a/djbdns/common.py b/djbdns/common.py index 6ef4e1c..1381011 100644 --- a/djbdns/common.py +++ b/djbdns/common.py @@ -67,6 +67,6 @@ def convert_ip(ip : str) -> str: if len(ip) == 8: # IPv4, eg. "7f000001" -> "7f 00 00 01" -> "127.0.0.1" return ".".join(map(str, pack(">L", int(ip, 16)))) - elif len(ip) == 32: - # IPv6 is actually simpler -- it's just a string-slicing operation. - return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)]) + + # IPv6 is actually simpler -- it's just a string-slicing operation. + return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)])