Testing for Remote Listener
Anyone know a good method for testing whether a remote UDP service is reachable - preferably without the use of netcat
or similar tools? TCP-based listeners are easy enough to do a cursory test: TCP gives you a basic pass/fail on a socket open attempt. Thus, a test like:
for HOST in ${SERVERLIST}
do
printf "Attempting service-connect to ${HOST}...\n"
SOCKTEST=$(timeout 5 bash -c 'cat < /dev/null > \
/dev/tcp/${HOST}/53')$?
if [[ ${SOCKTEST} -eq 0 ]]
then
printf "Socket-test passed.\n"
else
printf "Socket-test failed.\n"
fi
done
Is a fairly quick way to ensure that (in this case) the guys who provisioned a system pointed it to reachable DNS servers (didn't fat-finger any entries in the DHCP zone).
Using the above method-type for UDP doesn't really work - you get false successes. The specific case I'm trying to verify is NTPD accessibility. Using ntpdate <SERVER>
would be fine, but I'd need to do my tests like service ntpd stop ; <TESTS> ; service ntpd start
. Could also use ntpq -c peers
, but would really rather test servers individually rather than all at once. And, really, would overall prefer a generalizable method for UDP testing rather than having to do per-service test-definitions.
Any ideas?