2015-06-25 15:39:56 +02:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'rubydns'
|
|
|
|
require 'psych'
|
|
|
|
|
|
|
|
db_file = ARGV[0]
|
|
|
|
port = ARGV[1] || 5300
|
|
|
|
|
|
|
|
db = if File.file? db_file
|
|
|
|
$stderr.puts 'Found dns db'
|
|
|
|
Psych.load_file(db_file)
|
|
|
|
else
|
|
|
|
$stderr.puts 'Found no dns db. Use default db.'
|
|
|
|
|
|
|
|
{
|
|
|
|
/www\.example\.org/ => '1.1.1.1'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
interfaces = [
|
|
|
|
[:udp, "127.0.0.1", port],
|
|
|
|
[:tcp, "127.0.0.1", port]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Start the RubyDNS server
|
2015-11-12 00:30:26 +01:00
|
|
|
RubyDNS::run_server(listen: interfaces) do
|
2015-06-25 15:39:56 +02:00
|
|
|
db.each do |matcher, result|
|
|
|
|
match(matcher, Resolv::DNS::Resource::IN::A) do |transaction|
|
|
|
|
transaction.respond!(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|