Getting a DNS TXT record in Ruby
Try installing the 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
(Code tested on MacOS X - prints the Google SPF record)
See also @Alex's answer which is more idiomatic Ruby - Alex is the author of dnsruby
.
How can I copy the TXT record into the DNS configuration in portal azure?
Have a look at the documentation Verify your domain with a TXT record first. To verify domain ownership you should add TXT verification record generated by Google to DNS zone of your domain, then wait for a while and run check. To do it you should know which company provides you DNS service.
To solve your issue you should follow steps below:
- Look for DNS servers configured for your domain (NS records):
- via online service whois.net (if domain data was disclosed);
- via online service dnschecker.org;
- via Linux CLI with command:
dig NS YOUR_DOMAIN_NAME
- Find which company provides you DNS service:
- it could be obvious from step 1;
- via online service whois.net (if DNS service provided by registrar);
- via online service RIPE DB after converting DNS server FQDN name to IP.
- Add TXT record:
- in general it looks like this:
Type: TXT
Name/Host/Alias: @
Value/Answer/Destination: google-site-verification=VERIFICATION_CODE_GENERATED_BY_GOOGLE
Time to Live (TTL): 86400 or leave the default - for Azure you should follow documentation section "Add a TXT record for verification" and replace
MS=ms XXXXXXXX
withgoogle-site-verification=CODE_PROVIDED_BY_GOOGLE
; - for Cloudflare you should follow documentation.
UPDATE Accordingly to your update you use Cloudflare as a DNS service for your domain, because both DNS servers are related to Cloudflare: eric.ns.cloudflare.com
and tess.ns.cloudflare.com
. To add TXT record you should follow documentation. In addition, have a look at the instructions provided by Google.
UPDATE 2 In case you don't have access to your account at Cloudflare:
- try to restore access to your account at Cloudflare;
- collect information about services related to DNS and create DNS zone at Azure;
- change DNS servers at the registrar side to switch from Cloudflare to Azure (double check if you use any CLoudflare services).
DNS txt record invalid packet, FORMERR
In the example above supplied, I added an incorrect 00 (null terminator) at the end of the TXT-string. After removing the null terminator from the TXT records, the txt records now work on my nameserver.
Reverse DNS in Ruby?
Today I also needed reverse DNS lookup and I've found very simple standard solution:
require 'resolv'
host_name = Resolv.getname(ip_address_here)
It seems it uses timeout which helps in rough cases.
Related Topics
Library Not Loaded: /Usr/Local/Opt/Readline/Lib/Libreadline.6.Dylib (Loaderror)
Rails: How to Write Tests for a Ruby Module
What Is the Send() Method Used For
Profile a Rails Controller Action
Don't Create View Folder on Rails Generate Controller
Cannot Install Aptana Plugin on Eclipse 4.2
How to Make Rails 3 Assets Precompile Faster
How to Fire and Forget a Subprocess
Openssl, Rvm, Brew, Conflicting Error
How to Switch to Older Versions of the Ruby/Rails Environment
How to Controller (Start/Kill) a Background Process (Server App) in Ruby
How to Monitor Uptime of 20 Websites (Ping or Http) in Node.Js/Ror
Ruby on Rails 3 - Public Live Chat
Convert String to Decimal Number in Ruby
How to Use One Line Regular Expression to Get Matched Content