X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=bin%2Fdjbdns-logparse.py;h=31427a62f6155a1f6698871c9ee2b2e9e5617f41;hb=3ae973bcb6088d5cc25996a3888eab77d228dd88;hp=e9551834836476f41d18d7ae9fd9c4718ff8d5f2;hpb=60301b07b523d8d7d26a6c200c053ec134d25607;p=djbdns-logparse.git diff --git a/bin/djbdns-logparse.py b/bin/djbdns-logparse.py index e955183..31427a6 100755 --- a/bin/djbdns-logparse.py +++ b/bin/djbdns-logparse.py @@ -105,7 +105,46 @@ def convert_ip(ip : str): return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)]) -def decode_client(words, i): +def decode_client(words : list, i : int): + r""" + Helper function to decode the client field in a dnscache log + entry. + + There are two possible formats for the client field, + + 1. clientip:clientport, used by tcpopen/tcpclose entries, + 2. clientip:clientport:id, used by "query" entries. + + Parameters + ---------- + + words : list + The ``words`` list (a list of fields) from + :func:`handle_dnscache_log`. + + i : int + The index of the client field within ``words`` + + Returns + ------- + + Nothing; the ``i``th entry in the ``words`` list is modified + in-place. + + Examples + -------- + + >>> words = ["foo", "bar", "7f000001:9253", "quux"] + >>> decode_client(words, 2) + >>> words + ['foo', 'bar', '127.0.0.1:37459', 'quux'] + + >>> words = ["foo", "7f000001:a3db:4fb9", "bar", "quux"] + >>> decode_client(words, 1) + >>> words + ['foo', '127.0.0.1:41947 (id 20409)', 'bar', 'quux'] + + """ chunks = words[i].split(":") ip = convert_ip(chunks[0])