2

I'm developing a program which will work only if user connected to a Wi-Fi network (not ethernet, not even 3g and etc). How should I know that user is connected to a Wi-Fi (for Windows 7 and newer)?

Pang
  • 9,564
  • 146
  • 81
  • 122
Bablod
  • 101
  • 3
  • 12

2 Answers2

1

As said by user aditya (Check whether connected to a Wi-Fi network or not C#)

The part for checking internet connection is answered here:

C# checking Internet connection

The SSID part is answered here:

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

I think this is how it goes: Do a connection test (if you want to make sure a valid internet connection is ongoing) then check for connected SSID using the answer on the second question, if there is 1 or more(unlikely) connected SSIDs then you should know you are connected to a wireless network

Community
  • 1
  • 1
WalidSabihi
  • 192
  • 2
  • 10
  • 2
    I don't want to check Internet connection, I just want to be sure that user is connected to a Wireless network. Even if user connected to a network with ethernet, he'll have access to Internet. – Bablod Nov 15 '15 at 14:58
  • But the first step to know if the user's connected to a WiFi network is to have access to Internet no? the first link denotes checking Internet connection and the second shows getting SSID of wireless network which means you are connected to a WiFi network – WalidSabihi Nov 15 '15 at 15:01
  • Well, I don't want to get SSID, just to check a simple connection! and of course, I don't know how to do that. – Bablod Nov 15 '15 at 15:05
  • 1
    If you're getting a valid SSID, means you are connected to a wireless network! Besides, I don't know of any other way to achieve what you need – WalidSabihi Nov 15 '15 at 15:08
  • Ok, let me check that. – Bablod Nov 15 '15 at 15:13
0

This might help:

foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (netInterface.OperationalStatus == OperationalStatus.Up)
            {
                Console.Writeline(netInterface.NetworkInterfaceType.ToString()
            }
        }

MSDN the all-knowing has the following to say about the NetworkInterfaceType property:

https://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.networkinterfacetype(v=vs.110).aspx

Tombas
  • 111
  • 1
  • 10