Class IPAddress
Initializes a new instance of the IPAddress class.
public class IPAddress
- Inheritance
-
IPAddress
- Inherited Members
- Extension Methods
Constructors
IPAddress(byte[])
Initializes a new instance of the IPAddress class with the address specified as a Byte array.
public IPAddress(byte[] address)
Parameters
address
byte[]The byte array value of the IP address.
Remarks
The IPAddress is created with the System.Net.IPAddress.Address property set to address
.
If the length of address
is 4, IPAddress(Byte[]) constructs an IPv4 address; otherwise, an IPv6 address with a scope of 0 is constructed.
The byte array is assumed to be in network byte order with the most significant byte first in index position 0.
Exceptions
- ArgumentNullException
address
is null.- ArgumentException
address
contains a bad IP address.
IPAddress(byte[], long)
Initializes a new instance of a IPV6 IPAddress class with the address specified as a Byte array.
public IPAddress(byte[] address, long scopeid)
Parameters
address
byte[]The byte array value of the IP address.
scopeid
longThe long value of the scope identifier.
Remarks
The IPAddress is created with the System.Net.IPAddress.Address property set to address
.
If the length of address
is 4, IPAddress(Byte[]) constructs an IPv4 address; otherwise, an IPv6 address with a scope of 0 is constructed.
The byte array is assumed to be in network byte order with the most significant byte first in index position 0.
Exceptions
- ArgumentNullException
address
is null.- ArgumentException
address
contains a bad IP address.
IPAddress(long)
Initializes a new instance of the IPAddress class with the address specified as an Int64.
public IPAddress(long newAddress)
Parameters
newAddress
longThe long value of the IP address. For example, the value 0x2414188f in big-endian format would be the IP address "143.24.20.36".
Remarks
The IPAddress instance is created with the System.Net.IPAddress.Address property set to newAddress
.
The long value is assumed to be in network byte order.
Exceptions
- ArgumentOutOfRangeException
newAddress
< 0 ornewAddress
> 0x00000000FFFFFFFF
Fields
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 Any
Field Value
Remarks
The Bind(EndPoint) method uses the Any field to indicate that a Socket instance must listen for client activity on all network interfaces.
The Any field is equivalent to 0.0.0.0 in dotted-quad notation.
Broadcast
Provides the IP broadcast address. This field is read-only.
public static readonly IPAddress Broadcast
Field Value
Remarks
The Broadcast field is equivalent to 255.255.255.255 in dotted-quad notation.
IPv6Any
The Bind(EndPoint) method uses the IPv6Any field to indicate that a Socket must listen for client activity on all network interfaces.
public static readonly IPAddress IPv6Any
Field Value
IPv6Loopback
Provides the IP loopback address. This property is read-only.
public static readonly IPAddress IPv6Loopback
Field Value
Loopback
Provides the IP loopback address. This field is read-only.
public static readonly IPAddress Loopback
Field Value
Remarks
The Loopback field is equivalent to 127.0.0.1 in dotted-quad notation.
None
Provides an IP address that indicates that no network interface should be used. This field is read-only.
public static readonly IPAddress None
Field Value
Remarks
The Bind(EndPoint) uses the None field to indicate that a Socket must not listen for client activity.
The None field is equivalent to 255.255.255.255 in dotted-quad notation.
Properties
AddressFamily
Gets the address family of the IP address.
public AddressFamily AddressFamily { get; }
Property Value
- AddressFamily
Returns InterNetwork for IPv4 or InterNetworkV6 for IPv6.
IsIPv4MappedToIPv6
Gets whether the IP address is an IPv4-mapped IPv6 address.
public bool IsIPv4MappedToIPv6 { get; }
Property Value
- bool
true if the IP address is an IPv4-mapped IPv6 address; otherwise, false.
ScopeId
Get or Set IPV6 scope identifier.
public long ScopeId { get; set; }
Property Value
Methods
Equals(IPAddress)
Compares two IP addresses.
public bool Equals(IPAddress other)
Parameters
Returns
Equals(object)
Compares two IP addresses.
public override bool Equals(object other)
Parameters
Returns
GetAddressBytes()
Provides a copy of the IPAddress as an array of bytes in network order.
public byte[] GetAddressBytes()
Returns
GetDefaultLocalAddress()
Retrieves an IP address that is the local default address.
public static IPAddress GetDefaultLocalAddress()
Returns
- IPAddress
The default IP address.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
MapToIPv4()
Maps the IPAddress object to an IPv4 address.
public IPAddress MapToIPv4()
Returns
Remarks
Dual-stack sockets always require IPv6 addresses. The ability to interact with an IPv4 address requires the use of the IPv4-mapped IPv6 address format.
MapToIPv6()
Maps the IPAddress object to an IPv6 address.
public IPAddress MapToIPv6()
Returns
Remarks
Dual-stack sockets always require IPv6 addresses. The ability to interact with an IPv4 address requires the use of the IPv4-mapped IPv6 address format. Any IPv4 addresses must be represented in the IPv4-mapped IPv6 address format which enables an IPv6 only application to communicate with an IPv4 node. For example. IPv4 192.168.1.4 maps as IPV6 ::FFFF:192.168.1.4
Parse(string)
Converts an IP address string to an IPAddress instance.
public static IPAddress Parse(string ipString)
Parameters
ipString
stringA string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
Returns
ToString()
Converts an Internet address to its standard notation.
public override string ToString()
Returns
- string
A string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation.
Remarks
The ToString() method converts the IP address that is stored in the System.Net.IPAddress.Address property to either IPv4 dotted-quad or IPv6 colon-hexadecimal notation.
Operators
operator ==(IPAddress, IPAddress)
Indicates whether two IPAddress objects are equal.
public static bool operator ==(IPAddress a, IPAddress b)
Parameters
Returns
operator !=(IPAddress, IPAddress)
Indicates whether two IPAddress objects are not equal.
public static bool operator !=(IPAddress a, IPAddress b)