I have code that performs DNS lookups using Ruby's built-in Resolve::DNS
functionality and it works perfectly to resolve IP addresses to names (or any other type of applicable DNS lookup).
It is working against our internal nameservers, however occasionally I would like to see what external DNS is reporting.
In order to bounce an IP address up against Google's public DNS (8.8.8.8 / https://dns.google.com/), for example, I need to be able to make requests through our authenticated proxy.
I have tried setting http_proxy
and HTTPS_PROXY
at the command line (using known good syntax that works outside of Resolv::DNS
. I have also tried specifically using ENV['http_proxy'] = 'http://username:password@hostname:port'
(with both capitalization for the environment variable, of course).
Does anyone know how to make requests through a proxy with Resolv::DNS
?
Please note that I have other code that depends on using Resolv::DNS
so I am not looking for answers that attempt to leverage other Ruby gems/libraries for this task.
Here is my code that works when query internal DNS nameservers, but it will not work against Google DNS (it will just time out after a long period of time):
dns = Resolv::DNS.new(:nameserver => '8.8.8.8')
dns_ptr = dns.getnames('107.23.199.237') # logitech.com
p dns_ptr
Expected Output:
[#<Resolv::DNS::Name: ec2-ip-address-and-name-of-logitech.com-in-aws.com.>]