Is there a static method I can use to parse a String to check if it is an IP address, instead of having to initialize a new System.Net.IPAddress
instance?
This is what I am trying to achieve
System.Net.IPAddress throwawayIpAddress = new System.Net.IPAddress(Encoding.ASCII.GetBytes("127.0.0.1"));
System.Net.IPAddress.TryParse(baseUri.Host, out throwawayIpAddress);
baseUri
is a Uri
variable, and Host
is a string
. I am looking for something simpler such as:
System.Net.IPAddress.TryParse(baseUri.Host, out new System.Net.IPAddress(Encoding.ASCII.GetBytes("127.0.0.1"));
Due to the fact that the TryParse()
method expects a String
and an out IPAddress
reference, I cannot pass null
or a throwaway object directly.
Appreciate your advice on a simpler way to parse a String to test if it is an IP Address.