IPAddress.TryParse Method (String, IPAddress)


Determines whether a string is a valid IP address.

Namespace:   System.Net
Assembly:  System (in System.dll)

Public Shared Function TryParse (
	ipString As String,
	<OutAttribute> ByRef address As IPAddress
) As Boolean


Type: System.String

The string to validate.

Type: System.Net.IPAddress

The IPAddress version of the string.

Return Value

Type: System.Boolean

true if ipString was able to be parsed as an IP address; otherwise, false.

Note that this method accepts as valid an ipString value that can be parsed as an Int64, and then treats that Int64 as the long value of an IP address in network byte order, similar to the way that the IPAddress constructor does. This means that this method returns true if the Int64 is parsed successfully, even if it represents an address that's not a valid IP address. For example, if ipString is "1", this method returns true even though "1" (or is not a valid IP address and you might expect this method to return false. Fixing this bug would break existing apps, so the current behavior will not be changed. Your code can avoid this behavior by ensuring that it only uses this method to parse IP addresses in dotted-decimal format.

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Return to top