Shell Script To Build dnstop Utility To Displays Various Tables Of DNS Server Traffic

in Categories Software Build Scripts last updated March 5, 2010
#!/bin/bash
# A shell script to build dnstop utility to displays various tables 
# of DNS traffic on your network including bind 9 server stats.
# -------------------------------------------------------------------------
# Tested under CentOS / RHEL / Fedora Linux only.
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Last updated on Mar/05/2010
# -------------------------------------------------------------------------
# Home page: http://dns.measurement-factory.com/tools/dnstop/
VERSION="-20090128"
URL="http://dns.measurement-factory.com/tools/dnstop/src/dnstop${VERSION}.tar.gz"
FILE="${URL##*/}"
DLHOME="/opt"
SOFTWARE="dnstop"
DEST="${FILE%.tar.gz}"
ETH="eth0"
 
[[ "$2" != "" ]] && ETH="$2"
 
[[ `id -u` -ne 0 ]] && { echo "$0: You must be root user to run this script. Run it as 'sudo $0'"; exit 1; }
 
case "$1" in
    download) 
        wget $URL -O "${DLHOME}/$FILE"
        ;;
    build) 
        echo "Building ${SOFTWARE}...."
        # this needs some improvements, bur right now I am just gonna try to install it ;( 
	yum -y install libpcap-devel ncurses-devel &>/dev/null
        [[ ! -f "${DLHOME}/$FILE" ]] &&  wget $URL -O "${DLHOME}/$FILE"
        cd "${DLHOME}"
        tar -zxvf $FILE
        cd "$DEST"
        ./configure
        make
        make install
        grep -q 'alias dnstop' $HOME/.bashrc        
        [ $? -ne 0 ] && echo "alias dnstop='/usr/local/bin/dnstop -l 6 ${ETH}'" >> $HOME/.bashrc
        ;;
    *) echo "Usage: $0 {download|build} [eth0|eth1]"
esac

dnstop

From the man page:

dnstop is a small tool to listen on device or to parse the file savefile and collect and print statistics on the local network’s DNS traffic. You must have read access to /dev/bpf*.

How Do I Use This Script?

Download type the following command:
./script.sh build
/usr/local/bin/dnstop -l 6 eth0


Share this on:

4 comment

  1. The script surely would work only on rpm-based Linuxes, as it uses the “yum” command.
    Maybe if you changed this one line to equivalent apt command…?

    Have a question? Post it on our forum!