I have a string that can either represent a host name (myip.noip.org, etc.) or it can represent a true address ("127.0.0.1"). What is the best way to resolve this to a System.Net.IPAddress?
Thanks in advance.
You can call Dns.GetHostEntry on an IP address or a hostname.
It even does reverse lookups for you.
If you don't need reverse lookup, you can call Dns.GetHostAddresses instead.
Dns.Resolve is now listed as obsolete; looks like Dns.GetHostEntry is the direct replacement.Use the IPAddress.Parse method for IP addresses.
IPAddress address = IPAddress.Parse("127.0.0.1");
As mentioned by others, to resolve both IP addresses and host names, use Dns.GetHostEntry which:
Resolves a host name or IP address to an IPHostEntry instance.
IPHostEntry holds a collection of IP addresses in its AddressList property.