Created
May 1, 2013 17:47
-
-
Save hamstar/5496892 to your computer and use it in GitHub Desktop.
Simple DNS server in ruby. Tested and it works!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'rubydns' | |
$R = Resolv::DNS.new | |
Name = Resolv::DNS::Name | |
IN = Resolv::DNS::Resource::IN | |
Hosts = "/etc/dnsserv/hosts" | |
RubyDNS::run_server(:listen => [[:udp, "0.0.0.0", 5300]]) do | |
# For this exact address record, return an IP address | |
match(/.*/) do |transaction| | |
line = `grep "#{transaction.name}" #{Hosts}`.split("\n").first | |
transaction.passthrough!($R) if $?.exitstatus != 0 | |
ip = line.split("\t").first | |
transaction.respond!(ip) | |
end | |
# Default DNS handler | |
otherwise do |transaction| | |
transaction.passthrough!($R) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10.0.0.80 dev.test.org | |
8.8.8.8 dns.gg.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment