Tag Archives: bind

quick and dirty dns lint

I run a DNS server that I and a lot of my friends use. The problem with it being “free” and being between friends is sometimes people forget to tell you if they have switched DNS serving arrangements or just haven’t kept the registration.  I wrote a quick and dirty script, thanks to the whois ruby gem, to check to see if all the domains listed in Bind9‘s named.conf are still registered and if so do they still have our nameserver listed as one of the nameservers.  g0ff asked me for a copy, so I thought it might be useful to share with others.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'rubygems'
require 'whois'
 
zones = Array.new
ZONE_RE = /^zone "(\w+.\w+)" in/
File.open(ARGV[0]) do |f|
  f.each_line do |line|
    md = ZONE_RE.match(line.chomp)
    zones << md[1] unless md.nil?
  end
end
 
NS_RE = /^#{ARGV[1]}$/i
 
zones.each do |zone|
  c = Whois::Client.new
 
  begin
    domain = c.query(zone)
 
    if domain.registered?
      if domain.nameservers.detect { |ns| !NS_RE.match(ns.name).nil? }.nil?
        puts "#{domain.domain} doesn't seem to have us as a dns server"
      end
    else
      puts "#{zone} doesn't appear to be registered"
    end
  rescue Whois::ResponseIsThrottled
    sleep 120
    c = Whois::Client.new
    retry
  end
end