« Ouf | 2007 : non merci Nicolas » |
Mass DNS Test
Imagine that you are dirty with your DNS server. You make some modifications very often and you are not sure when your DNS server is up, RFC and running. Here is a little script which will automatically test some domains and send emails in case of error.
In order to test domains validity, I use DNSdoctor (http://www.dnsdoctor.org/), a fork from Zonecheck (http://www.afnic.fr/outils/zonecheck), a tool developed to perform verifications on the quality of the configuration (it is mandatory with a .fr to have the domain correctly configured). DNSdoctor exists with a few GUI :
- the web interface - http://demo.dnsdoctor.org/
- a classical application using GTK
- a command line application
Of course, I am using the last one to perform the automatic testing system.
As DNSdoctor has been made using Ruby, I made this script with this language (I don't want to have to install python for this script). It will call the DNSdoctor with the appropriate parameters. If an error is detected, it will send an email associated to the domain in the configuration.
If an error occurs, this kind of email will be sent :
ZONE : ledru.info. NS <= : akira.ecranbleu.org. [195.137.249.60] NS : radium.meaweb.com. [83.217.68.103] NS : trunks.ecranbleu.org. [195.137.249.61] [> ICMP answer w> Host doesn't reply to ICMP requests (firewall?) => radium.meaweb.com./83.217.68.103 => akira.ecranbleu.org./195.137.249.60 => trunks.ecranbleu.org./195.137.249.61 [> UDP connectivity f> Server doesn't listen/answer on port 53 for UDP protocol | Ref: IETF RFC1035 (p.32 4.2. Transport) | The DNS assumes that messages will be transmitted as datagrams or in | a byte stream carried by a virtual circuit. While virtual circuits can | be used for any DNS activity, datagrams are preferred for queries due | to their lower overhead and better performance. `----- -- -- - - - => radium.meaweb.com./83.217.68.103 ==> FAILURE (and 3 warning(s))
#!/usr/bin/ruby require 'net/smtp' ###########" Parameters ############### pathCommand="export LANG=en_EN; /usr/bin/dnsdoctor" paramCommand="-q -vn,d,x,-c " logFile="/tmp/massDNS.log" subject="DNS error" from="tech@linesurf.com" testDNS= [ {'domain'=>'ecranbleu.org', 'email'=>'email@domain.com'}, {'domain'=>'ledru.info', 'email'=>'email@mondomaine.com'} ] def sendmail(from,to,content) # --- Send using class methods msg = [ "Subject: Test\n", "\n", content ] Net::SMTP.start('localhost') do |server| server.sendmail( msg, from , [ to ] ) end end ######### Don't edit under ############# command="#{pathCommand} #{paramCommand} " for domain in testDNS puts "Processing of #{domain['domain']}" commandLine=command + domain['domain'] system(commandLine +' > '+ logFile +' 2>&1') if ($? != 0) content="" IO.foreach(logFile) { |line| content+=line } sendmail(from,domain['email'],content) puts "Erreur" end File.delete(logFile) end
Edit : comments are closed. Thank you spammer.
1 comment

Very interesting site ! Good work ! Ñongratulations :)