I have a string that can either represent the host name (myip.noip.org, etc.), or it can be a true address ("127.0.0.1"). What is the best way to enable this for System.Net.IPAddress?
Thanks in advance.
Use the method Dns.GetHostAddresses. This will handle both domain names and raw IP address values
Dns.GetHostAddresses
IPAddress[] array = DNs.GetHostAddresses(theString);
You can call Dns.GetHostEntryto the IP address or host name.It even does a reverse search for you.
Dns.GetHostEntry
If you do not need a reverse search, you can call instead Dns.GetHostAddresses.
IPAddress.Parse IP-.
IPAddress.Parse
IPAddress address = IPAddress.Parse("127.0.0.1");
, IP-, Dns.GetHostEntry, :
IP- IPHostEntry.
IPHostEntrystores a set of IP addresses in a property AddressList.
IPHostEntry
AddressList