.NET Networking APIs

IPInterfaceProperties Class

Provides a set of properties that describe the configuration of a network interface.

Namespace: System.Net.IP
Assembly: System.Net.Primitives (in System.Net.Primitives.dll)

Inheritance

Remarks

The IPInterfaceProperties class allows you to retrieve specific network interface configuration details that are relevant to IP protocols. This can include information such as DNS server addresses, WINS server addresses, default gateway information, and whether IPv6 is enabled for the interface.

Instances of this class are typically obtained through the GetIPProperties() method of the NetworkInterface class.

Properties

DhcpServerAddresses

Type: UnicastIPAddressInformationCollection
Access: Read-only

Gets the collection of unicast IP addresses that are assigned to the DHCP servers for this interface.

DnsAddresses

Type: UnicastIPAddressInformationCollection
Access: Read-only

Gets the collection of unicast IP addresses that are assigned to the DNS servers for this interface.

DnsSuffix

Type: System.String
Access: Read-only

Gets the DNS suffix for this interface.

GatewayAddresses

Type: GatewayIPAddressInformationCollection
Access: Read-only

Gets the collection of gateway IP addresses for this interface.

IsDnsEnabled

Type: System.Boolean
Access: Read-only

Indicates whether DNS is enabled for this interface.

IsTemporaryStaticAddress

Type: System.Boolean
Access: Read-only

Indicates whether the IP address assigned to this interface is a temporary static address.

NetbiosNodeType

Type: NetbiosNodeType
Access: Read-only

Gets the NetBIOS node type for this interface.

WinsServersAddresses

Type: UnicastIPAddressInformationCollection
Access: Read-only

Gets the collection of unicast IP addresses that are assigned to the WINS servers for this interface.

Methods

GetIPv4Properties()

Returns: IPv4InterfaceProperties
Access: Public

Returns an object that contains IPv4-specific configuration properties for this interface.

public IPv4InterfaceProperties GetIPv4Properties();

GetIPv6Properties()

Returns: IPv6InterfaceProperties
Access: Public

Returns an object that contains IPv6-specific configuration properties for this interface.

public IPv6InterfaceProperties GetIPv6Properties();

Example

The following C# code example demonstrates how to retrieve and display the DNS server addresses for all network interfaces on the system.

using System;
using System.Net;
using System.Net.NetworkInformation;

public class NetworkInfo
{
    public static void Main()
    {
        NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

        foreach (NetworkInterface adapter in networkInterfaces)
        {
            IPInterfaceProperties ipProperties = adapter.GetIPProperties();
            Console.WriteLine($"Interface: {adapter.Name} ({adapter.Description})");
            Console.WriteLine($"  Operational Status: {adapter.OperationalStatus}");

            UnicastIPAddressInformationCollection dnsServers = ipProperties.DnsAddresses;
            if (dnsServers.Count > 0)
            {
                Console.WriteLine("  DNS Servers:");
                foreach (UnicastIPAddressInformation dnsServer in dnsServers)
                {
                    Console.WriteLine($"    - {dnsServer.Address}");
                }
            }
            else
            {
                Console.WriteLine("  DNS Servers: Not configured");
            }
            Console.WriteLine();
        }
    }
}