Skip to content

Instantly share code, notes, and snippets.

@kubicek
Created September 30, 2009 22:33
Show Gist options
  • Save kubicek/198522 to your computer and use it in GitHub Desktop.
Save kubicek/198522 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'eventmachine'
require 'dnsruby'
module RedirectServer
def receive_data data
send_data <<EOF
HTTP/1.1 301 Moved Permanently
Location: http://www.daukce.cz/
Content-Type: text/html
Content-Length: 162
<html><head><title>Moved</title></head><body><h1>Moved</h1><p>This page has moved to <a href="http://www.daukce.cz/">http://www.daukce.cz/</a>.</p></body></html>
EOF
end
end
module DnsServer
def receive_data packet
message = Dnsruby::Message.decode(packet)
question = message.question()[0]
message.add_answer( Dnsruby::RR.create( "#{question.qname} 300 IN CNAME server4.railshosting.cz" ) )
message.header.rcode = Dnsruby::RCode.NoError
send_data message.encode
end
end
EventMachine::run {
EventMachine::start_server "127.0.0.1", 80, RedirectServer
EventMachine::open_datagram_socket "127.0.0.1", 53, DnsServer
puts 'running server'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment