Sha256: a063eebda7ffa44d0037fe0ca48337f688142d74cabdacc17bfc1a8f07a57343

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'rexec'
require 'rexec/daemon'
require 'rubydns'

module Meltdown
  class DnsServer < RExec::Daemon::Base
    class << self
      IN = Resolv::DNS::Resource::IN

      def run
        # don't buffer output (for realtime debugging)
        $stdout.sync = true
        $stderr.sync = true

        # listen on same port as Pow, registered in /etc/resolver/dev
        RubyDNS::run_server(:listen => [[:udp, "0.0.0.0", 20560]]) do
          match(/.*\.dev$/, IN::A) do |match, transaction|
            logger.info "DNS match A    : #{transaction.inspect}"
            transaction.respond!("127.0.0.1")
          end

          match(/.*\.dev$/, IN::AAAA) do |match, transaction|
            logger.info "DNS match AAAA : #{transaction.inspect}"
            transaction.respond!("::1")
          end

          match("1.0.0.127.in-addr.arpa", IN::PTR) do |transaction|
            logger.info "DNS match PTR  : #{transaction.inspect}"
            transaction.respond!(Name.create("default.dev."))
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
meltdown-0.1.2 lib/meltdown/dns_server.rb
meltdown-0.1.1 lib/meltdown/dns_server.rb
meltdown-0.1.0 lib/meltdown/dns_server.rb