<p dir="ltr">Why don't you use dig+grep+sed in bash?</p>
<div class="gmail_quote">On Apr 6, 2016 14:44, "Trevor Cordes" <<a href="mailto:trevor@tecnopolis.ca">trevor@tecnopolis.ca</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a program that needs to do DNS lookups, etc. Things will go Really<br>
Wonky if there's a problem with DNS (from a client perspective). Thus,<br>
I'd like the program to be able to check if DNS isn't working. In this<br>
particular setup, the box runs its own named with a view setup for<br>
resolution/caching.<br>
<br>
In particular, I want to test that:<br>
1. named is running and answering calls to its port<br>
2. named is getting real answers from the net (i.e. doing its recursive<br>
resolution properly; and port 53 to outside NS's isn't being blocked)<br>
3. (rare) root NS's aren't getting DDoS'd / whole world's DNS is down<br>
<br>
I want to do this inside a perl or php program, but any language<br>
pseudo-code will be fine as a template. I don't want to run a full-blown<br>
monitoring program separately.<br>
<br>
Ideally, I'll have some php like:<br>
function IsDnsOk() {<br>
check named<br>
check resolution ok<br>
}<br>
<br>
To be used possibly like:<br>
while (!IsDnsOk()) {<br>
sleep 10;<br>
}<br>
$important_dns_result=gethostbyname($host);<br>
<br>
<br>
But I want any check to be fairly lightweight. I don't want to fire off<br>
useless DNS lookups to root name servers at a potential rate of thousands<br>
a minute. Plus, I guess I have to worry about cached results making<br>
things look ok when they are really not. Any solution I implement will<br>
probably be designed to only run these tests once a minute or something,<br>
which won't catch the instant DNS goes down, but will mitigate the damage<br>
caused.<br>
<br>
I can think of a number of fairly simple tests I can try, but they feel<br>
kind of kludgy. Is there a better way?<br>
<br>
Ideally, the PHP calls, like gethostbyname would be able to return a<br>
"down" status, but they decided to lump in to the same return value<br>
failure due to no dns record and failure due to any other reason.<br>
<br>
Thanks!<br>
_______________________________________________<br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" rel="noreferrer" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
</blockquote></div>