Find Information about your Network Cards using C# or VB.NET

Here’s a small snippet of code of how to find out which network cards are enabled and able to transmit data on your machine. Here’s the code.

Add a reference to System.Net.NetworkInformation

C#

var nics = NetworkInterface.GetAllNetworkInterfaces()
.Where(o => o.OperationalStatus == OperationalStatus.Up);

foreach (var item in nics)
{
Response.Write(item.Description + "<br />");
Response.Write(item.Name + "<br />");
Response.Write(item.Speed + "<br />");
Response.Write(item.NetworkInterfaceType + "<br /><br />");
}

VB.NET

Dim nics = NetworkInterface.GetAllNetworkInterfaces()_
.Where(Function(o) o.OperationalStatus = OperationalStatus.Up)

For Each item In nics
Response.Write(item.Description & "<br />")
Response.Write(item.Name & "<br />")
Response.Write(item.Speed & "<br />")
Response.Write(item.NetworkInterfaceType & "<br /><br />")
Next item

The output is below:

clip_image002

No comments:

Post a Comment