.NET API Documentation

Namespace

System.Net

Class

IPInterfaceAddress

Provides information about an IP address and the network interface to which it is bound.

Inheritance

System.Object → System.Net.IPInterfaceAddress

Properties

NameTypeDescription
AddressIPAddressThe IP address assigned to the interface.
PrefixLengthintThe length of the network prefix (subnet mask) in bits.
NetworkInterfaceNetworkInterfaceThe network interface that the address belongs to.
IsDnsEligibleboolIndicates whether the address is DNS-eligible.
IsTransientboolSpecifies whether the address is transient (e.g., DHCP assigned).

Methods

public override string ToString();

Returns a string that represents the current IPInterfaceAddress.

Examples

C#
PowerShell
// Retrieve all IPInterfaceAddress objects on the local machine
using System;
using System.Net;
using System.Net.NetworkInformation;

class Program
{
    static void Main()
    {
        foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
        {
            IPInterfaceProperties ipProps = ni.GetIPProperties();
            foreach (UnicastIPAddressInformation addr in ipProps.UnicastAddresses)
            {
                var ipInterface = new IPInterfaceAddress
                {
                    Address = addr.Address,
                    PrefixLength = addr.PrefixLength,
                    NetworkInterface = ni,
                    IsDnsEligible = addr.IsDnsEligible,
                    IsTransient = addr.IsTransient
                };

                Console.WriteLine(ipInterface);
            }
        }
    }
}
# List IPInterfaceAddress information using PowerShell
Get-NetIPAddress | ForEach-Object {
    $interface = Get-NetIPInterface -InterfaceIndex $_.InterfaceIndex
    [PSCustomObject]@{
        Address        = $_.IPAddress
        PrefixLength   = $_.PrefixLength
        InterfaceAlias = $interface.InterfaceAlias
        IsDnsEligible  = $_.AddressState -eq 'Preferred'
        IsTransient    = $_.AddressFamily -eq 'IPv4' -and $_.State -eq 'Preferred'
    }
} | Format-Table -AutoSize

See Also