Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the IP address of a domain

How can I find the IP address of an arbitrary domain? I want to get the IP address from the DNS server.

like image 959
nag Avatar asked Apr 21 '11 10:04

nag


3 Answers

require 'socket'
IPSocket::getaddress('www.google.com') #=> "74.125.79.147"
like image 70
Michael Kohl Avatar answered Oct 12 '22 12:10

Michael Kohl


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")
like image 39
lulalala Avatar answered Oct 12 '22 13:10

lulalala


Try going through the shell

domain = "google.com"
`host #{domain}`.match(/(\d{1,3}\.){3}\d{1,3}/).to_s
#=> "74.125.39.99"
like image 2
edgerunner Avatar answered Oct 12 '22 12:10

edgerunner