0

I’m working on a C# application. I need to know when the application connects to a different Wi-Fi network. The tricky part here is that the application is assigned the same IP address on both Wi-Fi networks:

  1. The application is currently connected to Wi-Fi #1 with IP address 11.22.33.44.
  2. On the PC where the application runs, I disconnect the PC from Wi-Fi #1.
  3. The PC quickly connects to Wi-Fi #2 and is assigned the same IP address (in this example 11.22.33.44).
  4. The application receives the NetworkChange.NetworkAddressChanged event.
  5. The application loops in the network interfaces returned by NetworkInterface.GetAllNetworkInterfaces() in order to detect an IP address change (by checking if the IP address, assigned to a particular NetworkInterface.Id, has changed).
  6. The problem is that the network interface information has not changed (NetworkInterface.OperationalStatus is still UP and the IP address is the same).
  7. The NetworkChange.NetworkAvailabilityChanged event is not received. If the NetworkInterface.OperationalStatus was to DOWN and then back to UP, I could detect a change.

Any idea?

Is it possible to access the list of Wi-Fi network and find out which one the application is connected with?

Thanks!

ccaron
  • 71
  • 7

1 Answers1

0

Provided you are only interested in testing Wi-Fi networks, you could use the SSID to determine which network you are on.

Get SSID of the wireless network I am connected to with C# .Net on Windows Vista

Community
  • 1
  • 1
Kevin Burdett
  • 2,892
  • 1
  • 12
  • 19
  • Thanks for the answer. This solution is based on www.codeplex.com code. Can we do the same with code from .NET? – ccaron Feb 16 '16 at 16:34
  • This library is in .NET and can be installed via NuGet (https://www.nuget.org/packages/managedwifi/), but if you are trying to avoid external dependencies, you can go directly to the native API. Docs @ https://msdn.microsoft.com/en-us/library/ms705969.aspx That said, unless you are very familiar with calling native APIs from C#, I promise you will find this cumbersome, time consuming, and possibly infuriating :) – Kevin Burdett Feb 16 '16 at 18:03
  • **@Kevin Burdett** Effectively, I looked at the native API and let's say it's not simple. – ccaron Feb 16 '16 at 20:43
  • I will definitively use the nuget.org/packages/managedwifi library. Very complete. – ccaron Feb 17 '16 at 15:48