System.Net.IPAddress Class

public class IPAddress

Base Types

Object
  IPAddress

Assembly

System

Library

Networking

Summary

Represents an Internet Protocol (IP) address.

Description

An instance of the IPAddress class contains the value of an address on an IP network. This address is stored internally as a Int64 in network-byte-order.

[Note: Different conventions are in use for ordering bytes within multi-byte data types. All IP address values must be sent over the network in network-byte-order. Network-byte-order puts the most significant byte first (also known as big-endian order). On the host, the ordering of bytes is platform-specific and this ordering is referred to as host-byte-order.]

The IP address can be represented as four numbers in the range 0-255 separated by periods (for example, "192.168.1.2"), known as dotted-quad notation.

[Note: The address space is fragmented into different types determined by bits 31-28 as shown in the following table.

Bits 31-28Address type
0xxxclass A
10xxclass B
110xclass C
1110multicast
1111reserved
]

Instances of the IPAddress class are provided for common IP address values as shown in the following table.

FieldIP Address
Any0.0.0.0
Broadcast255.255.255.255
Loopback127.0.0.1
None255.255.255.255

See Also

System.Net Namespace

Members

IPAddress Constructors

IPAddress Constructor

IPAddress Methods

IPAddress.Equals Method
IPAddress.GetHashCode Method
IPAddress.HostToNetworkOrder(long) Method
IPAddress.HostToNetworkOrder(int) Method
IPAddress.HostToNetworkOrder(short) Method
IPAddress.IsLoopback Method
IPAddress.NetworkToHostOrder(long) Method
IPAddress.NetworkToHostOrder(int) Method
IPAddress.NetworkToHostOrder(short) Method
IPAddress.Parse Method
IPAddress.ToString Method

IPAddress Fields

IPAddress.Any Field
IPAddress.Broadcast Field
IPAddress.Loopback Field
IPAddress.None Field

IPAddress Properties

IPAddress.Address Property
IPAddress.AddressFamily Property


IPAddress Constructor

public IPAddress(long newAddress);

Summary

Constructs and initializes a new instance of the IPAddress class.

Parameters

newAddress
A Int64 containing the IP address in host-byte-order.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionnewAddress is less than 0 or greater than 0x00000000FFFFFFFF.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.Equals Method

public override bool Equals(object comparand);

Summary

Determines whether the current instance and the specified Object represent the same IP address.

Parameters

comparand
A Object to compare to the current instance.

Return Value

A Boolean where true indicates comparand is an instance of the IPAddress class and has the same System.Net.IPAddress.Address property value as the current instance; otherwise false .

Description

[Note: This method overrides System.Object.Equals(System.Object).

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for the current instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.HostToNetworkOrder(long) Method

public static long HostToNetworkOrder(long host);

Summary

Converts a Int64 from host-byte-order to network-byte-order.

Parameters

host
A Int64 in host-byte-order.

Return Value

A Int64 in network-byte-order.

Description

This method performs conversions on systems where the host-byte-order differs from network-byte-order. On systems where this is not the case, this method does nothing.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.HostToNetworkOrder(int) Method

public static int HostToNetworkOrder(int host);

Summary

Converts a Int32 from host-byte-order to network-byte-order.

Parameters

host
A Int32 in host-byte-order.

Return Value

A Int32 in network-byte-order.

Description

This method performs conversions on systems where the host-byte-order differs from network-byte-order. On systems where this is not the case, this method does nothing.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.HostToNetworkOrder(short) Method

public static short HostToNetworkOrder(short host);

Summary

Converts a Int16 from host-byte-order to network-byte-order.

Parameters

host
A Int16 in host-byte-order.

Return Value

A Int16 in network-byte-order.

Description

This method performs conversions on systems where the host-byte-order differs from network-byte-order. On systems where this is not the case, this method does nothing.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.IsLoopback Method

public static bool IsLoopback(IPAddress address);

Summary

Returns a Boolean that indicates whether the specified IP address is a loopback address.

Parameters

address
A IPAddress containing the IP address to check.

Return Value

true if address is a loopback address; otherwise false .

Description

All IP addresses of the form 127.X.Y.Z, where X, Y, and Z are in the range 0-255, are forwarded to the IP loopback address 127.0.0.1. The System.Net.IPAddress.Loopback address is used to specify the address of the local computer.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.NetworkToHostOrder(long) Method

public static long NetworkToHostOrder(long network);

Summary

Converts a Int64 from network-byte-order to host-byte-order.

Parameters

network
A Int64 in network-byte-order.

Return Value

A Int64 in host-byte-order.

Description

This method performs conversions on systems where the host-byte-order differs from network-byte-order. On systems where this is not the case, this method does nothing.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.NetworkToHostOrder(int) Method

public static int NetworkToHostOrder(int network);

Summary

Converts a Int32 from network-byte-order to host-byte-order.

Parameters

network
A Int32 in network-byte-order.

Return Value

A Int32 in host-byte-order.

Description

This method performs conversions on systems where the host-byte-order differs from network-byte-order. On systems where this is not the case, this method does nothing.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.NetworkToHostOrder(short) Method

public static short NetworkToHostOrder(short network);

Summary

Converts a Int16 from network-byte-order to host-byte-order.

Parameters

network
A Int16 in network-byte-order.

Return Value

A Int16 in host-byte-order.

Description

This method performs conversions on systems where the host-byte-order differs from network-byte-order. On systems where this is not the case, this method does nothing.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.Parse Method

public static IPAddress Parse(string ipString);

Summary

Converts a String representation of an IP address in dotted-quad notation, to a IPAddress instance.

Parameters

ipString
A String in dotted-quad notation containing the IP address to convert.

Return Value

A new IPAddress instance that represents the address specified in ipString.

Exceptions

Exception TypeCondition
ArgumentNullExceptionipString is null .
FormatExceptionipString is not a valid IP address.

Description

[Note: An example of a string in dotted-quad notation is "127.0.0.1".

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.ToString Method

public override string ToString();

Summary

Returns a String representation of the value of the current instance.

Return Value

A String representation of the current instance. The returned string is an IP address expressed in dotted-quad notation (for example, "192.168.1.2").

Description

[Note: The System.Net.IPAddress.ToString method converts the IP address stored in the System.Net.IPAddress.Address property of the current instance to a String containing the address in dotted-quad notation (for example, "192.168.1.2").

This method overrides System.Object.ToString.

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.Any Field

public static readonly IPAddress Any;

Summary

Indicates that the protocol will select which address to use.

Description

This field is read-only.

This is equivalent to System.Net.IPAddress.IPAddress (0x0000000000000000) and represents the address 0.0.0.0.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.Broadcast Field

public static readonly IPAddress Broadcast;

Summary

Provides the IP broadcast address.

Description

This field is read-only.

This is equivalent to System.Net.IPAddress.IPAddress (0x00000000FFFFFFFF) and represents the address 255.255.255.255.

This value is used to simultaneously address every host on the network.

[Note: Multiple fields are defined for this IP address based on prior art. This field is identical to System.Net.IPAddress.None.

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.Loopback Field

public static readonly IPAddress Loopback;

Summary

Provides the IP loopback address.

Description

This field is read-only.

This is equivalent to System.Net.IPAddress.IPAddress (0x000000000100007F) and represents the address 127.0.0.1.

The loopback address is used to specify the address of the local computer.

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.None Field

public static readonly IPAddress None;

Summary

Provides the IP address that indicates that no network interface should be used.

Description

This field is read-only.

This is equivalent to System.Net.IPAddress.IPAddress (0x00000000FFFFFFFF) and represents the address 255.255.255.255.

[Note: Multiple fields are defined for this IP address based on prior art. This field is identical to System.Net.IPAddress.Broadcast.

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.Address Property

public long Address { get; set; }

Summary

Gets or sets an Internet Protocol (IP) address.

Property Value

A Int64 containing the IP address in host-byte-order.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe value specified in a set operation is less than 0.

Description

[Note: To convert System.Net.IPAddress.Address to dotted-quad notation, use the System.Net.IPAddress.ToString method.

Values greater than 0x00000000FFFFFFFF are permitted for IPv6 extensibility.

]

See Also

System.Net.IPAddress Class, System.Net Namespace

IPAddress.AddressFamily Property

public AddressFamily AddressFamily { get; }

Summary

Gets the address family.

Property Value

System.Net.Sockets.AddressFamily.InterNetwork .

Description

This property is read-only.

See Also

System.Net.IPAddress Class, System.Net Namespace