1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/middleman-core/fixtures/preview-server-app/bin/dns_server.rb
2015-11-11 15:30:40 -08:00

33 lines
637 B
Ruby
Executable file

#!/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
RubyDNS::run_server(listen: interfaces) do
db.each do |matcher, result|
match(matcher, Resolv::DNS::Resource::IN::A) do |transaction|
transaction.respond!(result)
end
end
end