System.Net.IPAddress Class

Assembly: System.dll
Namespace: System.Net
Summary
Provides an Internet Protocol (IP) address.
C# Syntax:
[Serializable]
public class IPAddress
Remarks
The IPAddress class contains the address of a computer on an IP network.
Example
The following example creates an IPAddress instance and then uses that instance to perform a DNS query for host information:
 IPAddress myIP = IPAddress.Parse("192.168.1.2");
 
 IPHostEntry myHost = Dns.GetHostByAddress(myIP);
   

    
See also:
System.Net Namespace

System.Net.IPAddress Member List:

Public Constructors
ctor #1 Initializes a new instance of the IPAddress class with the specified address.
Public Fields
Any Provides an IP address indicating that the server should listen for client activity on all network interfaces. This field is read-only.
Broadcast Provides the IP broadcast address. This field is read-only.
Loopback Provides the IP loopback address. This field is read-only.
None Provides an IP address indicating that no network interface should be used. This field is read-only.
Public Properties
Address Read-write

An Internet Protocol (IP) address.
AddressFamily Read-only

Specifies the address family of the IP address.
Public Methods
Equals Overridden:
Compares two IP addresses.
GetHashCode Overridden:
Returns a hash value for an IP address.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
HostToNetworkOrder Overloaded:
HostToNetworkOrder(short host)

Converts a short value from host byte order to network byte order.
HostToNetworkOrder Overloaded:
HostToNetworkOrder(int host)

Converts an integer value from host byte order to network byte order.
HostToNetworkOrder Overloaded:
HostToNetworkOrder(long host)

Converts a long value from host byte order to network byte order.
IsLoopback Indicates whether the specified IP address is the loopback address.
NetworkToHostOrder Overloaded:
NetworkToHostOrder(short network)

Converts a short value from network byte order to host byte order.
NetworkToHostOrder Overloaded:
NetworkToHostOrder(int network)

Converts an integer value from network byte order to host byte order.
NetworkToHostOrder Overloaded:
NetworkToHostOrder(long network)

Converts a long value from network byte order to host byte order.
Parse Converts an IP address string to an IPAddress instance.
ToString Overridden:
Converts an Internet address to standard dotted-quad format.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.IPAddress Member Details

ctor #1
Summary
Initializes a new instance of the IPAddress class with the specified address.
C# Syntax:
public IPAddress(
   long newAddress
);
Parameters:

newAddress

The integer value of the IP address.

Remarks
The IPAddress instance is created with the IPAddress.Address property set to newaddress.

Return to top


Field: Any
Summary
Provides an IP address indicating that the server should listen for client activity on all network interfaces. This field is read-only.
C# Syntax:
public static readonly IPAddress Any;
Remarks
The Socket.Bind method uses the IPAddress.Any field to indicate that a Socket instance should listen for client activity on all network interfaces.

The IPAddress.Any field is equivalent to 0.0.0.0.

Return to top


Field: Broadcast
Summary
Provides the IP broadcast address. This field is read-only.
C# Syntax:
public static readonly IPAddress Broadcast;
Remarks
The IPAddress.Broadcast field is equivalent to 255.255.255.255 in dotted-quad notation.

Return to top


Field: Loopback
Summary
Provides the IP loopback address. This field is read-only.
C# Syntax:
public static readonly IPAddress Loopback;
Remarks
The IPAddress.Loopback field is equivalent to 127.0.0.1 in dotted-quad notation.

Return to top


Field: None
Summary
Provides an IP address indicating that no network interface should be used. This field is read-only.
C# Syntax:
public static readonly IPAddress None;
Remarks
The Socket.Bind method uses the IPAddress.None field to indicate that a Socket instance should not listen for client activity.

Return to top


Property: Address (read-write)
Summary
An Internet Protocol (IP) address.
C# Syntax:
public long Address {get; set;}
Remarks
To convert IPAddress.Address to dotted-quad notation, use the IPAddress.ToString method.

Return to top


Property: AddressFamily (read-only)
Summary
Specifies the address family of the IP address.
C# Syntax:
public AddressFamily AddressFamily {get;}

Return to top


Overridden Method: Equals(
   object comparand
)
Summary
Compares two IP addresses.
C# Syntax:
public override bool Equals(
   object comparand
);
Parameters:

comparand

An IPAddress instance to compare to the current instance.

Return Value:
true if the two address are equal; otherwise, false.
Remarks
The IPAddress.Equals method compares the current IPAddress instance with the comparand parameter and returns true if the two instance contain the same IP address.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~IPAddress();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Returns a hash value for an IP address.
C# Syntax:
public override int GetHashCode();
Return Value:
An integer hash value.
Remarks
The IPAddress.GetHashCode method returns a hash code of the IP address. This value can be used as a key in hash tables.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: HostToNetworkOrder(
   short host
)
Summary
Converts a short value from host byte order to network byte order.
C# Syntax:
public static short HostToNetworkOrder(
   short host
);
Parameters:

host

The number to convert expressed in host byte order.

Return Value:
A short value expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To enable computers that use different byte ordering, all integer values sent over the network are sent in network byte order.

The IPAddress.HostToNetworkOrder method converts multibyte integer values stored on the host system from the byte order used by the host to the byte order used by the network.

See also:
IPAddress.NetworkToHostOrder

Return to top


Overloaded Method: HostToNetworkOrder(
   int host
)
Summary
Converts an integer value from host byte order to network byte order.
C# Syntax:
public static int HostToNetworkOrder(
   int host
);
Parameters:

host

The number to convert expressed in host byte order.

Return Value:
An integer value expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To enable computers that use different byte ordering, all integer values sent over the network are sent in network byte order.

The IPAddress.HostToNetworkOrder method converts multibyte integer values stored on the host system from the byte order used by the host to the byte order used by the network.

See also:
IPAddress.NetworkToHostOrder

Return to top


Overloaded Method: HostToNetworkOrder(
   long host
)
Summary
Converts a long value from host byte order to network byte order.
C# Syntax:
public static long HostToNetworkOrder(
   long host
);
Parameters:

host

The number to convert expressed in host byte order.

Return Value:
A long value expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To enable computers that use different byte ordering, all integer values sent over the network are sent in network byte order.

The IPAddress.HostToNetworkOrder method converts multibyte integer values stored on the host system from the byte order used by the host to the byte order used by the network.

See also:
IPAddress.NetworkToHostOrder

Return to top


Method: IsLoopback(
   IPAddress address
)
Summary
Indicates whether the specified IP address is the loopback address.
C# Syntax:
public static bool IsLoopback(
   IPAddress address
);
Parameters:

address

An IP address.

Return Value:
true if address is the loopback address; otherwise false.
Remarks
The IPAddress.IsLoopback method compares address to IPAddress.Loopback and returns true if the two IP address are the same.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: NetworkToHostOrder(
   short network
)
Summary
Converts a short value from network byte order to host byte order.
C# Syntax:
public static short NetworkToHostOrder(
   short network
);
Parameters:

network

The number to convert expressed in network byte order.

Return Value:
A short value expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To enable computers that use different byte ordering, all integer values sent over the network are sent in network byte order.

The IPAddress.NetworkToHostOrder method converts multibyte integer values stored on the host system from the byte order used by the network to the byte order used by the host.

See also:
IPAddress.HostToNetworkOrder

Return to top


Overloaded Method: NetworkToHostOrder(
   int network
)
Summary
Converts an integer value from network byte order to host byte order.
C# Syntax:
public static int NetworkToHostOrder(
   int network
);
Parameters:

network

The number to convert expressed in network byte order.

Return Value:
An integer value expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To enable computers that use different byte ordering, all integer values sent over the network are sent in network byte order.

The IPAddress.NetworkToHostOrder method converts multibyte integer values stored on the host system from the byte order used by the network to the byte order used by the host.

See also:
IPAddress.HostToNetworkOrder

Return to top


Overloaded Method: NetworkToHostOrder(
   long network
)
Summary
Converts a long value from network byte order to host byte order.
C# Syntax:
public static long NetworkToHostOrder(
   long network
);
Parameters:

network

The number to convert expressed in network byte order.

Return Value:
A long value expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To enable computers that use different byte ordering, all integer values sent over the network are sent in network byte order.

The IPAddress.NetworkToHostOrder method converts multibyte integer values stored on the host system from the byte order used by the network to the byte order used by the host.

See also:
IPAddress.HostToNetworkOrder

Return to top


Method: Parse(
   string ipString
)
Summary
Converts an IP address string to an IPAddress instance.
C# Syntax:
public static IPAddress Parse(
   string ipString
);
Parameters:

ipString

A string containing an IP address in dotted-quad notation (for example, "192.168.1.2").

Return Value:
An IPAddress instance.
Exceptions
Exception Type Condition
ArgumentNullException ipString is null.
FormatException ipString is not a valid IP address.
Remarks
The static IPAddress.Parse method creates an IPAddress instance from an IP address expressed in dotted-quad ("192.168.1.2") notation.

Return to top


Overridden Method: ToString()
Summary
Converts an Internet address to standard dotted-quad format.
C# Syntax:
public override string ToString();
Return Value:
A string containing the IP address in dotted-quad format (for example, "192.168.1.2").
Remarks
The IPAddress.ToString method converts the IP address stored in the IPAddress.Address property is converted to dotted-quad notation (for example, "192.168.1.2").

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.