O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


NETWORKING HACK

simple "nsping"
there's no need to install a separate utility to run "nsping", you have "dig" already ...

Contributed by:
jose nazario
[11/16/03 | Discuss (0) | Link to this hack]

a simple network diagnostic tool to determine the health and reachability of name servers is nsping. as the name suggests you ping a name server, not with an ICMP echo request but with a (random) lookup. the time interval it takes to get a reply back is what you're after. serious lags can indicate network issues. the tool nsping is a standalone binary, and on most UN*X systems it's another package to install. however, almost everyone already has dig installed, part of the BIND package. dig is a complex name server query and diagnostic tool. one useful feature of it is that it reports the amount of time it takes to perform it's query in milliseconds ... exactly what we're after. so, let's use dig to do exactly what nsping does and trim down the answer to look like nsping. all we have to do is a random lookup and report only the query time. this simple shell hack uses the built in random number generator from ksh (i think the tool can work in bash, too) and awk to trim down the query from dig.

#!/bin/ksh
SERVER=$1
dig @${SERVER} -t a ${RANDOM}.${RANDOM}${RANDOM}.${RANDOM} | \
        awk '{if ($0 ~/Query/) print $4" "$5}'
put this in your path and ping a name server:
$ nsping ns.oreilly.com      
97 msec
i have used this in the past to query the root nameservers as a network connectivity monitor (with much success).

See also: man dig
"dns & bind", the book from o'reilly
"sed & awk", another book from o'reilly


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.