Converts an IP address string to an IPAddress instance.
Assembly: System (in System.dll)
The static method creates an IPAddress instance from an IP address expressed in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
The method accepts octal, decimal, and hexadecimal number formats in the ipString parameter for an IPv4 address, even when mixed. The method can't handle Unicode characters in the ipString parameter.
The number of parts (each part is separated by a period) in ipString determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address, convenient for specifying a class A address, puts the leading part in the first byte and the trailing part in the right-most three bytes of the network address. A three part address, convenient for specifying a class B address, puts the first part in the first byte, the second part in the second byte, and the final part in the right-most two bytes of the network address. For example:
Number of parts and example ipString
IPv4 address for IPAddress
1 -- "65536"
2 -- "20.2"
2 -- "20.65535"
3 -- "128.1.2"
4 -- "0xC0.0xA8.0x1.0x01"
4 -- "0300.0250.01.01"
4 -- "0300.0xA8.1.1"
The following code converts a string that contains an IP address, in dotted-quad notation for IPv4 or in colon-hexadecimal notation for IPv6, into an instance of the IPAddress class. Then it uses the overloaded ToString method to display the address in standard notation.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2