class Droxy::DNSServer
Constants
- IN
Attributes
port[R]
tld[R]
Public Class Methods
new(tld:, port: @tld, @port = tld, port)
click to toggle source
# File lib/droxy/dns_server.rb, line 9 def initialize tld:, port: @tld, @port = tld, port end
Public Instance Methods
fallback_dns()
click to toggle source
# File lib/droxy/dns_server.rb, line 38 def fallback_dns @_fallback_dns ||= RubyDNS::Resolver.new([ [:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53] ]) end
interfaces()
click to toggle source
# File lib/droxy/dns_server.rb, line 13 def interfaces [ [:udp, "0.0.0.0", port], [:tcp, "0.0.0.0", port] ] end
translate(&block)
click to toggle source
# File lib/droxy/dns_server.rb, line 17 def translate &block srv = self # yay, metaprogramming RubyDNS.run_server listen: interfaces do logger.level = Logger::INFO match /(\w+)\.#{srv.tld}/, IN::AAAA do next! end match /(\w+)\.#{srv.tld}/, IN::A do |transaction, capture| if ip = block.call(capture[1]) transaction.respond! ip else next! end end otherwise { |transaction| transaction.passthrough! srv.fallback_dns } end end