-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.rb
44 lines (35 loc) · 1.01 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'rubygems'
require 'optparse'
require 'eventmachine'
require_relative 'ppdns'
require_relative 'options'
op = {}
optparse = OptionParser.new do |opts|
op[:verbose] = false
opts.on('-v', '--verbose', 'Enable verbose output') do
op[:verbose] = true
end
op[:port] = 53
opts.on('-p', '--port', 'The port to run the server on') do |val|
op[:port] = val.to_i
end
op[:local_ip] = '0.0.0.0'
opts.on('-l', '--local', 'The local IPv4 IP to run the server on, defaults to 0.0.0.0') do |val|
op[:local_ip] = val.to_s
end
op[:dns_ip] = '8.8.8.8'
opts.on('-d', '--dns', 'The IP location of the DNS server to forward all other requests, defaults to 8.8.8.8 (Google)') do |val|
op[:dns_ip] = val.to_s
end
end
optparse.parse!
options = Options.instance
options.load(op)
if options.verbose == true then
puts "Starting up..."
puts "Binding to #{op[:local_ip]}:#{op[:port].to_s}"
end
EM.run do
# EM.start_server op[:local_ip], op[:port], P2PDNS
EM.open_datagram_socket options.local_ip, options.port, P2PDNS
end