1 out of 4 rated this helpful - Rate this topic

IPAddress.Address Property

Note: This API is now obsolete.

An Internet Protocol (IP) address.

Namespace:  System.Net
Assembly:  System (in System.dll)
[ObsoleteAttribute("This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. http://go.microsoft.com/fwlink/?linkid=14202")]
public long Address { get; set; }

Property Value

Type: System.Int64
The long value of the IP address.
Exception Condition
SocketException

The address family is InterNetworkV6.

This property is obsolete. Use GetAddressBytes.

To convert Address to dotted-quad notation, use the ToString method.

The following example uses the Address parameter to retrieve the IP address of the IPAddress instance.


public void PrintAddress(String IpAddressString)
{
  // Creates an instance of the IPAddress for the specified IP string in 
  // dotted-quad notation. 
  IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
  Console.WriteLine("\nThe IP address '" + IpAddressString + "' is {0}", hostIPAddress.ToString()); 
}


.NET Framework

Supported in: 1.0
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2
Obsolete (compiler warning) in 1.1

.NET Framework Client Profile

Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5 SP1

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
This should not be obsolete
The NetworkToHostOrder and HostToNetworkOrder methods require an integer value for input and only output integers.  I'm writing API / pinvoke code and need to be able to marshal a IPAddress value to it's Network order integer value which has nothing to do with comparision operations.  You should add an overload to the coversion functions to take an IPAddress object as an input param.  This is especially true if you're going to make it taboo to use the IPAddress.Address property to retreive the underlying value.
Obsolete??? really?, then why is it still there?
Seems to me that this was marked as obsolete in the early frameworks, but like every useful looking function in the ridiculous .net framework, there is no logical way to get a long value from a dotted IP, hence another intentional brickwall built by MS.

Forget about the built in functions because you will be forced into more silly scenarios such as network byte order, etc. that is designed to eventually make you give up out of frustration!

Solution: (Take note of that word, MS! s-o-l-u-t-i-o-n) After getting the dotted IP address, run it through this function and you should have the correct numeric long value that (backwards thinking .net will understand):

' Use this for .net apps such as socket binding, etc. (the one at the bottom is for the rest of the computer world.)
Public Function IPAddressToNumber_DOTNETSTYLE(ByVal IP_StrValue As String) As Long
    Try
        Dim IPAddress As IPAddress = IPAddress.Parse(IP_StrValue)
            With IPAddress
                Dim IPbyte0 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(3))
                Dim IPbyte1 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(2))
                Dim IPbyte2 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(1))
                Dim IPbyte3 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(0))
                Return ((256 ^ 3) * IPbyte0) + ((256 ^ 2) * IPbyte1) + (256 * IPbyte2) + (IPbyte3)
            End With
                Catch ex As Exception
            Return 0L
    End Try
End Function

' For a Normal Logical Address conversion(which will be backwards in .net but correct for every other scenario in the universe),
' one would actually reverse the byte calculations like the following.

Public Function IPAddressToNumber(ByVal IP_StrValue As String) As Long
    Try
        Dim IPAddress As IPAddress = IPAddress.Parse(IP_StrValue)
            With IPAddress
                Dim IPbyte0 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(0))
                Dim IPbyte1 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(1))
                Dim IPbyte2 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(2))
                Dim IPbyte3 As Long = Convert.ToInt32(IPAddress.GetAddressBytes(3))
                Return ((256 ^ 3) * IPbyte0) + ((256 ^ 2) * IPbyte1) + (256 * IPbyte2) + (IPbyte3)
            End With
                Catch ex As Exception
            Return 0L
    End Try
End Function
' I could list literally thousands of these pitfalls that were created by ms and have never been fixed even since the first .net framework.
Check Range
This should not be obsolete, because of range validation
private bool NotInRange(string ip, string ipStart, string ipEnd)
    {
        bool result = false;

        System.Net.IPAddress iStart  = System.Net.IPAddress.Parse(ipStart);
        System.Net.IPAddress iEnd   = System.Net.IPAddress.Parse(ipEnd);
        System.Net.IPAddress iToCheck = System.Net.IPAddress.Parse(ip);

        if (iStart.Address <= iToCheck.Address && iEnd.Address >= iToCheck.Address)
        {
            result = true;
        }

        return result;
    }

Perhaps NOT obsolete

I'm not entirely convinced this should be marked as obsolete: it's still extremely useful for calculating network ranges based on CIDR notation or when given a subnet mask in the form of an IP address:

IPAddress ip = IPAddress.Parse("192.168.1.151");
IPAddress subnetMask = IPAddress.Parse("255.255.255.192");
IPAddress networkId = new IPAddress(ip.Address & subnetMask.Address);
Console.WriteLine(networkId.ToString()); // will print 192.168.1.128