IPInterfaceProperties Class

Provides information about network interfaces that support Internet Protocol version 4 (IPv4) or Internet Protocol version 6 (IPv6).

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

public abstract class IPInterfaceProperties

This class provides access to configuration and address information for network interfaces that support IPv4 or IPv6. You do not create instances of this class; they are returned by the GetIPProperties method.

To access IPv4-specific properties, use the object returned by the GetIPv4Properties method. To access IPv6-specific properties, use the object returned by the GetIPv6Properties method.

The following code example displays address information.

public static void ShowIPAddresses(IPInterfaceProperties adapterProperties)
{
    IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
    if (dnsServers != null)
    {
        foreach (IPAddress dns in dnsServers)
        {
            Console.WriteLine("  DNS Servers ............................. : {0}", 
                dns.ToString()
           );
        }
    }
    IPAddressInformationCollection anyCast = adapterProperties.AnycastAddresses;
    if (anyCast != null)
    {
        foreach (IPAddressInformation any in anyCast)
        {
            Console.WriteLine("  Anycast Address .......................... : {0} {1} {2}", 
                any.Address,
                any.IsTransient ? "Transient" : "", 
                any.IsDnsEligible ? "DNS Eligible" : ""
            );
        }
        Console.WriteLine();
    }

    MulticastIPAddressInformationCollection multiCast = adapterProperties.MulticastAddresses;
    if (multiCast != null)
    {
        foreach (IPAddressInformation multi in multiCast)
        {
            Console.WriteLine("  Multicast Address ....................... : {0} {1} {2}", 
                multi.Address,
                multi.IsTransient ? "Transient" : "", 
                multi.IsDnsEligible ? "DNS Eligible" : ""
            );
        }
        Console.WriteLine();
    }
    UnicastIPAddressInformationCollection uniCast = adapterProperties.UnicastAddresses;
    if (uniCast != null)
    {
        string lifeTimeFormat = "dddd, MMMM dd, yyyy  hh:mm:ss tt";
        foreach (UnicastIPAddressInformation uni in uniCast)
        {
            DateTime when;

            Console.WriteLine("  Unicast Address ......................... : {0}", uni.Address);
            Console.WriteLine("     Prefix Origin ........................ : {0}", uni.PrefixOrigin);
            Console.WriteLine("     Suffix Origin ........................ : {0}", uni.SuffixOrigin);
            Console.WriteLine("     Duplicate Address Detection .......... : {0}", 
                uni.DuplicateAddressDetectionState);

            // Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM 
            // if en-us is the current culture. 

            // Calculate the date and time at the end of the lifetimes.    
            when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime);
            when = when.ToLocalTime();    
            Console.WriteLine("     Valid Life Time ...................... : {0}", 
                when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
            );
            when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime);   
            when = when.ToLocalTime();      
            Console.WriteLine("     Preferred life time .................. : {0}", 
                when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
            ); 

            when = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime);
            when = when.ToLocalTime(); 
            Console.WriteLine("     DHCP Leased Life Time ................ : {0}", 
                when.ToString(lifeTimeFormat,System.Globalization.CultureInfo.CurrentCulture)
            );
        }
        Console.WriteLine();
    }
}
void ShowIPAddresses(IPInterfaceProperties* adapterProperties)
{
    IPAddressInformationCollection* dnsServers = adapterProperties->DnsAddresses;
    if (dnsServers != 0)
    {
        System::Collections::IEnumerator* myEnum = dnsServers->GetEnumerator();
        while (myEnum->MoveNext())
        {
            IPAddressInformation* dns = __try_cast<IPAddressInformation*>(myEnum->Current);
            Console::WriteLine(S"  DNS Servers ............................. : {0} ({1} {2})", 
                dns->Address,
                dns->IsTransient ? S"Transient" : S"", 
                dns->IsDnsEligible ? S"DNS Eligible" : S""
                );
        }
    }
    IPAddressInformationCollection* anyCast = adapterProperties->AnycastAddresses;
    if (anyCast != 0)
    {
        System::Collections::IEnumerator* myEnum1 = anyCast->GetEnumerator();
        while (myEnum1->MoveNext())
        {
            IPAddressInformation* any = __try_cast<IPAddressInformation*>(myEnum1->Current);
            Console::WriteLine(S"  Anycast Address .......................... : {0} {1} {2}", 
                any->Address,
                any->IsTransient ? S"Transient" : S"", 
                any->IsDnsEligible ? S"DNS Eligible" : S""
                );
        }
        Console::WriteLine();
    }

    IPAddressInformationCollection* multiCast = adapterProperties->MulticastAddresses;
    if (multiCast != 0)
    {
        System::Collections::IEnumerator* myEnum2 = multiCast->GetEnumerator();
        while (myEnum2->MoveNext())
        {
            IPAddressInformation* multi = __try_cast<IPAddressInformation*>(myEnum2->Current);
            Console::WriteLine(S"  Multicast Address ....................... : {0} {1} {2}", 
                multi->Address,
                multi->IsTransient ? S"Transient" : S"", 
                multi->IsDnsEligible ? S"DNS Eligible" : S""
                );
        }
        Console::WriteLine();
    }
    IPUnicastAddressInformationCollection* uniCast = adapterProperties->UnicastAddresses;
    if (uniCast != 0)
    {
        String* lifeTimeFormat = S"dddd, MMMM dd, yyyy  hh:mm:ss tt";
        System::Collections::IEnumerator* myEnum3 = uniCast->GetEnumerator();
        while (myEnum3->MoveNext())
        {
            IPUnicastAddressInformation* uni = __try_cast<IPUnicastAddressInformation*>(myEnum3->Current);
            DateTime when;

            Console::WriteLine(S"  Unicast Address ......................... : {0}", uni->Address);
            Console::WriteLine(S"     Prefix Origin ........................ : {0}", __box(uni->PrefixOrigin));
            Console::WriteLine(S"     Suffix Origin ........................ : {0}", __box(uni->SuffixOrigin));
            Console::WriteLine(S"     Duplicate Address Detection .......... : {0}", __box(uni->DuplicateAddressDetectionState));

            // Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM
            // if en-us is the current culture.

            // Calculate the date and time at the end of the lifetimes.    
            when = DateTime::UtcNow + TimeSpan::FromSeconds((double)uni->AddressValidLifetime);
            when = when.ToLocalTime();    
            Console::WriteLine(S"     Valid Life Time ...................... : {0}", 
                when.ToString(lifeTimeFormat,System::Globalization::CultureInfo::CurrentCulture)
                );
            when = DateTime::UtcNow + TimeSpan::FromSeconds((double)uni->AddressPreferredLifetime);   
            when = when.ToLocalTime();      
            Console::WriteLine(S"     Preferred life time .................. : {0}", 
                when.ToString(lifeTimeFormat,System::Globalization::CultureInfo::CurrentCulture)
                ); 

            when = DateTime::UtcNow + TimeSpan::FromSeconds((double)uni->DhcpLeaseLifetime);
            when = when.ToLocalTime(); 
            Console::WriteLine(S"     DHCP Leased Life Time ................ : {0}", 
                when.ToString(lifeTimeFormat,System::Globalization::CultureInfo::CurrentCulture)
                );
        }
        Console::WriteLine();
    }
}

System.Object
  System.Net.NetworkInformation.IPInterfaceProperties

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft