T
T
TechNOIR2018-12-27 10:09:01
C++ / C#
TechNOIR, 2018-12-27 10:09:01

C#. How do I get the IPv4 of my physical NIC, excluding other vmware, hyperv, etc virtual adapters?

Good afternoon.
Please tell me how to get IPv4 of my physical network card, excluding other virtual adapters vmware, hyperv, etc.?
I get a list of adapters, then a list of IP, it contains both IPv6 and IPv4 and several virtual adapters. Is there any way to filter out only a single physical card and its IPv4?
thanks in advance

var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (var network in networkInterfaces)
            {
                var properties = network.GetIPProperties();

                Console.WriteLine(network.Name);
                foreach (UnicastIPAddressInformation ip in network.GetIPProperties().UnicastAddresses)
                {
                        Console.WriteLine(ip.Address);
                    

                }

            }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question