转发请求 UDPSocket
我有一个基本的 ruby 程序,它监听端口 (53),接收数据,然后发送到另一个位置(Google DNS 服务器 - 8.8.8.8)。回复不会返回到原来的目的地,或者我没有正确转发它们。
这是代码。注意我正在使用 EventMachine
require 'rubygems'
require 'eventmachine'
module DNSServer
def post_init
puts 'connected'
end
def receive_data(data)
# Forward all data
conn = UDPSocket.new
conn.connect '8.8.8.8', 53
conn.send data, 0
conn.close
p data.unpack("H*")
end
def unbind
puts 'disconnected'
end
end
EM.run do
EM.open_datagram_socket '0.0.0.0', 53, DNSServer
end
任何关于原因或调试技巧的想法将不胜感激。
I have a basic ruby program, that listens on a port (53), receives the data and then sends to another location (Google DNS server - 8.8.8.8). The responses are not going back to their original destination, or I'm not forwarding them correctly.
Here is the code. NB I'm using EventMachine
require 'rubygems'
require 'eventmachine'
module DNSServer
def post_init
puts 'connected'
end
def receive_data(data)
# Forward all data
conn = UDPSocket.new
conn.connect '8.8.8.8', 53
conn.send data, 0
conn.close
p data.unpack("H*")
end
def unbind
puts 'disconnected'
end
end
EM.run do
EM.open_datagram_socket '0.0.0.0', 53, DNSServer
end
Any thoughts as to why or tips to debug, would be most appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
明显的问题是:
send
而不是connect
#send_data
)到原始客户端这似乎有效:
The obvious problems are:
send
instead ofconnect
#send_data
) to the original clientThis seems to work: