#!/usr/bin/env awk
#
# Returns the top N DNS queries
#
# Dependencies:
#   - dnsDecode
#
# Examples:
#   - tawk 'topDnsQ()' file.txt
#   - tawk 'topDnsQ(5)' file.txt

@include "aggrrep"
@include "hdr"
@include "port"
@include "strisempty"
@include "_validate_col"

function topDnsQ(n) {
    _validate_col("dnsQname")
    if (hdr()) {
        if (__PRIHDR__) print $dnsQname, "Flows"
    } else if (!strisempty($dnsQname) && !port(137)) { # ignore NBNS
        aggrrep($dnsQname, "flows", n)
    }
}
