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

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

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