NetworkInterface Class

Namespace: System.Net.NetworkInformation

Assembly: System

Summary

Provides information about network interfaces on the local computer.

Syntax

public abstract class NetworkInterface

Remarks

The NetworkInterface class allows you to retrieve detailed information about all network interfaces installed on a computer, including their status, type, IP addresses, MAC addresses, and performance statistics.

You can use the static GetAllNetworkInterfaces method to get an array of all NetworkInterface objects available on the system.

Methods

Properties

Example

The following example iterates through all network interfaces on the local computer and displays their names, types, and operational status.

using System; using System.Net.NetworkInformation; public class NetworkInfoExample { public static void Main(string[] args) { NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); Console.WriteLine("Network Interfaces:"); Console.WriteLine("-----------------"); foreach (NetworkInterface ni in interfaces) { Console.WriteLine($"Name: {ni.Name}"); Console.WriteLine($" Description: {ni.Description}"); Console.WriteLine($" Type: {ni.NetworkInterfaceType}"); Console.WriteLine($" Status: {ni.OperationalStatus}"); Console.WriteLine($" MAC Address: {ni.GetPhysicalAddress().ToString()}"); IPInterfaceProperties ipProps = ni.GetIPProperties(); if (ipProps != null) { Console.WriteLine($" IP Address(es):"); foreach (UnicastIPAddressInformation ip in ipProps.UnicastAddresses) { Console.WriteLine($" - {ip.Address}"); } } Console.WriteLine(); } } }