Flareon
A cloudflare DNS over HTTPs resolver client library.
Cloudflare’s DNS over HTTPs endpoint supports JSON format for querying DNS data -- and this gem helps to use it!
Installation
$ gem install flareon
Usage
Perform a basic DNS query over HTTPs:
Flareon.query("google.com")
# => {
# "Status"=>0,
# "TC"=>false,
# "RD"=>true,
# "RA"=>true,
# "AD"=>false,
# "CD"=>false,
# "Question"=>[{"name"=>"google.com.", "type"=>1}],
# "Answer"=>[{"name"=>"google.com.", "type"=>1, "TTL"=>83, "data"=>"172.217.1.46"}]
# }
Single-threaded DNS query (IPv6) over HTTPs for multiple domains:
domains = ["google.com", "github.com", "microsoft.com", "apple.com"]
results = Flareon.batch_query(domains, type: "AAAA")
Multi-threaded DNS query (IPv4) over HTTPs for multiple domains:
domains = ["google.com", "github.com", "microsoft.com", "apple.com"]
results = Flareon.batch_query_multithreaded(domains, threads: 4)
Get the raw JSON response:
json = Flareon.query("google.com", json: true)
Specify DNS query type:
Flareon.query("google.com", type: "A")
Flareon.query("google.com", type: "AAAA")
Flareon.query("google.com", type: "MX")
The nslookup
method is an alias for the query
method:
Flareon.nslookup("google.com")
The dig
method is an alias for the query
method:
Flareon.dig("google.com")
Check if a given name is resolvable:
Flareon.resolve?("google.com")
# => true
Resolve a given domain to an IP address:
Flareon.resolve("google.com")
# => "172.217.1.46"
Resolve a given domain to an IPv4 address:
Flareon.resolve("google.com")
Flareon.resolve("google.com", type: "A")
Flareon.resolve("google.com", type: 1)
Resolve a given domain to an IPv6 address:
Flareon.resolve("google.com", type: "AAAA")
Flareon.resolve("google.com", type: 28)
Resolve a give domain to all IPv4 and IPv6 addresses:
ip_addresses = Flareon.resolve_all("google.com")
# or
Flareon.resolve_all("google.com") do |ip_address|
# do something with each ip_address
puts ip_address
end
Inspiration
Saw hrbrmstr working on dnsflare and wanted something similiar in Ruby.
License
The gem is available as open source under the terms of the MIT License.