Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Net.​IPAddress
Assembly: System.Net.Primitives
Inheritance: object → IPAddress
Implemented Interfaces
- ISpanFormattable (Inherits: IFormattable)
- ISpanParsable`1 (Inherits: IParsable<​IPAddress>)
- IUtf8SpanFormattable
- IUtf8SpanParsable`1
Provides an Internet Protocol (IP) address.
Fields and Constants
public static readonly
IPAddress
Any
Provides an IP address that indicates that the server must listen for client activity on all network interfaces. This field is read-only.
public static readonly
IPAddress
Broadcast
Provides the IP broadcast address. This field is read-only.
public static readonly
IPAddress
IPv6Any
The <see cref="M:System.Net.Sockets.Socket.Bind(System.Net.EndPoint)" /> method uses the <see cref="F:System.Net.IPAddress.IPv6Any" /> field to indicate that a <see cref="T:System.Net.Sockets.Socket" /> must listen for client activity on all network interfaces.
public static readonly
IPAddress
IPv6Loopback
Provides the IP loopback address. This property is read-only.
public static readonly
IPAddress
IPv6None
Provides an IP address that indicates that no network interface should be used. This property is read-only.
public static readonly
IPAddress
Loopback
Provides the IP loopback address. This field is read-only.
public static readonly
IPAddress
None
Provides an IP address that indicates that no network interface should be used. This field is read-only.
Properties
public
long
Address
An Internet Protocol (IP) address.
public
AddressFamily
AddressFamily
Gets the address family of the IP address.
public
bool
IsIPv4MappedToIPv6
Gets whether the IP address is an IPv4-mapped IPv6 address.
public
bool
IsIPv6LinkLocal
Gets whether the address is an IPv6 link local address.
public
bool
IsIPv6Multicast
Gets whether the address is an IPv6 multicast global address.
public
bool
IsIPv6SiteLocal
Gets whether the address is an IPv6 site local address.
public
bool
IsIPv6Teredo
Gets whether the address is an IPv6 Teredo address.
public
bool
IsIPv6UniqueLocal
Gets whether the address is an IPv6 Unique Local address.
public
long
ScopeId
Gets or sets the IPv6 address scope identifier.
Methods
public
bool
Equals​(object comparand)
Compares two IP addresses.
Returns <see langword="true" /> if the two addresses are equal; otherwise, <see langword="false" /> .
comparand
An <see cref="T:System.Net.IPAddress" /> instance to compare to the current instance.
public
byte[]
GetAddressBytes​()
Provides a copy of the <see cref="T:System.Net.IPAddress" /> as an array of bytes in network order.
Returns A <see cref="T:System.Byte" /> array.
public
int
GetHashCode​()
Returns a hash value for an IP address.
Returns An integer hash value.
public static
short
HostToNetworkOrder​(short host)
Converts a short value from host byte order to network byte order.
Returns A short value, expressed in network byte order.
host
The number to convert, expressed in host byte order.
public static
int
HostToNetworkOrder​(int host)
Converts an integer value from host byte order to network byte order.
Returns An integer value, expressed in network byte order.
host
The number to convert, expressed in host byte order.
public static
long
HostToNetworkOrder​(long host)
Converts a long value from host byte order to network byte order.
Returns A long value, expressed in network byte order.
host
The number to convert, expressed in host byte order.
public static
bool
IsLoopback​(IPAddress address)
Indicates whether the specified IP address is the loopback address.
Returns <see langword="true" /> if <paramref name="address" /> is the loopback address; otherwise, <see langword="false" /> .
address
An IP address.
public static
bool
IsValidUtf8​(ReadOnlySpan<​byte> utf8Text)
Determines whether the provided span contains a valid <see cref="T:System.Net.IPAddress" /> .
utf8Text
The text to parse.
public static
bool
IsValid​(ReadOnlySpan<​char> ipSpan)
Determines whether the provided span contains a valid <see cref="T:System.Net.IPAddress" /> .
ipSpan
The text to parse.
public
IPAddress
MapToIPv4​()
Maps the <see cref="T:System.Net.IPAddress" /> object to an IPv4 address.
Returns Returns <see cref="T:System.Net.IPAddress" /> .
An IPv4 address.
public
IPAddress
MapToIPv6​()
Maps the <see cref="T:System.Net.IPAddress" /> object to an IPv6 address.
Returns Returns <see cref="T:System.Net.IPAddress" /> .
An IPv6 address.
public static
short
NetworkToHostOrder​(short network)
Converts a short value from network byte order to host byte order.
Returns A short value, expressed in host byte order.
network
The number to convert, expressed in network byte order.
public static
int
NetworkToHostOrder​(int network)
Converts an integer value from network byte order to host byte order.
Returns An integer value, expressed in host byte order.
network
The number to convert, expressed in network byte order.
public static
long
NetworkToHostOrder​(long network)
Converts a long value from network byte order to host byte order.
Returns A long value, expressed in host byte order.
network
The number to convert, expressed in network byte order.
public static
IPAddress
Parse​(ReadOnlySpan<​char> ipSpan)
Converts an IP address represented as a character span to an <see cref="T:System.Net.IPAddress" /> instance.
Returns The converted IP address.
ipSpan
A character span that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
public static
IPAddress
Parse​(string ipString)
Converts an IP address string to an <see cref="T:System.Net.IPAddress" /> instance.
Returns An <see cref="T:System.Net.IPAddress" /> instance.
ipString
A string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
public static
IPAddress
Parse​(ReadOnlySpan<​byte> utf8Text)
Parses a span of UTF-8 characters into a value.
Returns The result of parsing <paramref name="utf8Text" /> .
utf8Text
The span of UTF-8 characters to parse.
public
string
ToString​()
Converts an Internet address to its standard notation.
Returns A string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation.
public
bool
TryFormat​(Span<​byte> utf8Destination,
Int32& bytesWritten)
public static
bool
TryParse​(ReadOnlySpan<​char> ipSpan,
IPAddress&? address)
public static
bool
TryParse​(ReadOnlySpan<​byte> utf8Text,
IPAddress&? result)
public
bool
TryWriteBytes​(Span<​byte> destination,
Int32& bytesWritten)
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object