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
Name | Type | Description |
---|---|---|
Address | IPAddress | The IP address assigned to the interface. |
PrefixLength | int | The length of the network prefix (subnet mask) in bits. |
NetworkInterface | NetworkInterface | The network interface that the address belongs to. |
IsDnsEligible | bool | Indicates whether the address is DNS-eligible. |
IsTransient | bool | Specifies 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