Click here to Skip to main content
15,889,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello.
How to get all network adapters (enabled and disabled) using C#?
Thanks.

What I have tried:

NetworkInterface.GetIPProperties Method ()
NetworkInterface.GetAllNetworkInterfaces Method ()
Posted
Updated 8-Jul-17 6:15am
Comments
Maciej Los 8-Jul-17 9:00am    
And what's the problem?

Try using WMI to query the hardware list useful page here Find only physical network adapters with WMI Win32_NetworkAdapter class[^]
 
Share this answer
 
Example:
C#
using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq.Expressions;
    using System.Management;
    using System.Threading;


        // Returns the list of Network Interfaces installed
        public static List<string> GetNicNames()
        {
            var nicNames = new List<string>();
            var mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            var moc = mc.GetInstances();

            foreach (var mo in moc)
            {
                // if ((bool)mo["ipEnabled"])
                {
                    nicNames.Add(mo["Caption"].ToString());
                }
            }

            return nicNames;
        }
 
Share this answer
 
v2
Comments
Mikolaj98p 9-Jul-17 7:01am    
This display only enabled nics. http://mikolaj98p.hostfree.pw/SS/ScreenShot_20170709130518.png

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900