How can I find the IP address of an arbitrary domain? I want to get the IP address from the DNS server.
require 'socket'
IPSocket::getaddress('www.google.com') #=> "74.125.79.147"
Resolv is on a higher level than Socket, so will use more resources. However it has the ability to find all the ip addresses of a domain
require 'resolv'
Resolv.getaddresses("www.ruby-lang.org")
Try going through the shell
domain = "google.com"
`host #{domain}`.match(/(\d{1,3}\.){3}\d{1,3}/).to_s
#=> "74.125.39.99"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With