在 Ruby 中获取 DNS TXT 记录 [英] Getting a DNS TXT record in Ruby
本文介绍了在 Ruby 中获取 DNS TXT 记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从 DNS 记录中获取 txt 字段.
有没有 ruby api 来做这样的事情?
I need to get the txt field from the DNS record.
Is there any ruby api to do something like this?
nslookup -q=txt xxxx.com
推荐答案
尝试安装 dnsruby gem.
代码得到积极维护,并用于一些重要的生产系统.
The code is actively maintained, and used in some significant production systems.
require 'rubygems'
require 'dnsruby'
include Dnsruby
# Use the system configured nameservers to run a query
res = Dnsruby::Resolver.new
ret = res.query("google.com", Types.TXT)
print ret.answer
(在 MacOS X 上测试的代码 - 打印 Google SPF 记录)
(Code tested on MacOS X - prints the Google SPF record)
另见@Alex 的回答,它更符合 Ruby 的习惯——Alex 是 dnsruby
的作者.
See also @Alex's answer which is more idiomatic Ruby - Alex is the author of dnsruby
.
这篇关于在 Ruby 中获取 DNS TXT 记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文