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






About The Author

Malcolm Sheridan is a Microsoft awarded MVP in ASP.NET and regular presenter at conferences and user groups throughout Australia. Being an ASP.NET Insider, his focus is on web technologies and has been for the past 10 years. He loves working with ASP.NET MVC these days and also loves getting his hands dirty with JavaScript. He also blogs regularly at DotNetCurry.com. Follow him on twitter @malcolmsheridan

No comments: