-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathppdns.rb
43 lines (37 loc) · 811 Bytes
/
ppdns.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
require 'rubygems'
require 'eventmachine'
require 'net/dns/packet'
require 'socket'
require_relative 'options'
class P2PDNS < EventMachine::Connection
def post_init
@options = Options.instance
if @options.verbose == true
puts 'connected'
end
end
def receive_data(data)
original_packet = Net::DNS::Packet::parse(data)
if @options.verbose == true
puts 'Question:'
p original_packet.question
end
sock = UDPSocket.open
sock.do_not_reverse_lookup = true
sock.connect @options.dns_ip, 53
sock.send data, 0
answer = sock.recv 4096
sock.close
answer_parsed = Net::DNS::Packet::parse(answer)
if @options.verbose == true
puts 'Answer:'
p answer_parsed.answer
end
send_data answer
end
def unbind
if @options.verbose == true
puts 'disconnected'
end
end
end