From 5d9b0f026de83a7dbbda656d7486c46d320cee1e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 15 Sep 2022 20:20:19 -0400 Subject: [PATCH] bin/djbdns-logparse.py: more docs for convert_ip(). --- bin/djbdns-logparse.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bin/djbdns-logparse.py b/bin/djbdns-logparse.py index 31427a6..e6a6759 100755 --- a/bin/djbdns-logparse.py +++ b/bin/djbdns-logparse.py @@ -82,11 +82,25 @@ query_drop_reason = { } -def convert_ip(ip : str): +def convert_ip(ip : str) -> str: """ - Convert a hex string representing an IP address to conventional - human-readable form, ie. dotted-quad decimal for IPv4, and - 8 colon-separated hex shorts for IPv6. + Convert a hex string representing an IP address to + human-readable form. + + Parameters + ---------- + + ip : str + The hexadecimal representation of either an IPv4 or an IPv6 + address. + + Returns + ------- + + The usual decimal dotted-quad representation is returned for an + IPv4 address. IPv6 addresses are returned almost as-is, but with + colons inserted in the appropriate places, between every four + characters. Examples -------- @@ -95,7 +109,6 @@ def convert_ip(ip : str): '127.0.0.1' >>> convert_ip("00000000000000000000ffff7f000001") '0000:0000:0000:0000:0000:ffff:7f00:0001' - """ if len(ip) == 8: # IPv4, eg. "7f000001" -> "7f 00 00 01" -> "127.0.0.1" -- 2.44.2