How can I get an IP address, given a domain name?
For example: www.test.com
views:
362answers:
2Also note it is PLURAL - and not all of them may work at a given time.
TomTom
2010-03-17 12:35:22
True, but i think it rare case that this method returns more then one address, especially in case of internet domains.
Andrey
2010-03-17 12:37:36
Andrey: Try `Dns.GetHostAddresses("google.com");`.
Brian Rasmussen
2010-03-17 12:41:34
@Brian - six IPs! WOW! so you need to store them all and pick next if one doesn't work.
Andrey
2010-03-17 13:00:53
+2
A:
You could use the GetHostAddresses method:
var address = Dns.GetHostAddresses("www.test.com")[0];
Darin Dimitrov
2010-03-17 12:36:29
@Andrey: If more than one, it would just ignore the rest. If 0, I guess it would crash :p
Svish
2010-03-17 12:39:59
@Moshe, in VB.NET : `Dim address = Dns.GetHostAddresses("www.test.com")(0)`
Darin Dimitrov
2010-03-17 12:40:28