How can I find the IP address of an arbitrary domain? I want to get the IP address from the DNS server.
Asked
Active
Viewed 6,172 times
6 Answers
36
require 'socket'
IPSocket::getaddress('www.google.com') #=> "74.125.79.147"

Michael Kohl
- 66,324
- 14
- 138
- 158
13
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")

lulalala
- 17,572
- 15
- 110
- 169
2
Try going through the shell
domain = "google.com"
`host #{domain}`.match(/(\d{1,3}\.){3}\d{1,3}/).to_s
#=> "74.125.39.99"

edgerunner
- 14,873
- 2
- 57
- 69
1
Try this code:
require 'resolv'
puts Resolv.getaddresses("www.panfu.dk")

Tunaki
- 132,869
- 46
- 340
- 423

Rehman Ahmed
- 61
- 1
- 1
- 5
0
you always can enter http://who.is/ and enter the url of the ip you're seeking for

Ori Wiesel
- 488
- 2
- 8
- 26
-4
This is the java script code which will retrun the client's IP as json object
<script type="text/javascript">
function knowYourIP(json){
document.write(json.ip);
}
<script type="text/javascript" src="http://jsonip.appspot.com/?callback=knowYourIP"></script>

9ikhan
- 1,177
- 3
- 11
- 22
-
-1 OP was not looking for client address, but for a way to look up the IP of an arbitrary domain. – Michael Kohl Apr 21 '11 at 13:16
-
okies, i misunderstood the question. but can't we get it thru like ping www.google.com? – 9ikhan Apr 21 '11 at 14:40
-
1OP wanted a Ruby answer, he got a Ruby answer and it was accepted. :-) – Michael Kohl Apr 21 '11 at 15:05