I need to know how to get all network interfaces using IPv4 . Or just wireless and Ethernet.
To get information about all network interfaces, I use the following:
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { if(ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { Console.WriteLine(ni.Name); } }
And to get all hosted IPv4 addresses of a computer:
IPAddress [] IPS = Dns.GetHostAddresses(Dns.GetHostName()); foreach (IPAddress ip in IPS) { if (ip.AddressFamily == AddressFamily.InterNetwork) { Console.WriteLine("IP address: " + ip); } }
But how to get the network interface and its right ipv4 address?
c # ip-address network-interface
Murhaf Sousli Mar 24 '12 at 20:17 2012-03-24 20:17
source share