Getting a Dns Txt Record in Ruby

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:

  1. 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

  1. 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.

  1. 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 with google-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:

  1. try to restore access to your account at Cloudflare;
  2. collect information about services related to DNS and create DNS zone at Azure;
  3. change DNS servers at the registrar side to switch from Cloudflare to Azure (double check if you use any CLoudflare services).

whois

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



Leave a reply



Submit