I already know how to check if there's a connection to the internet. But I want this(function) to be called when the user plugs a lan line in or connect to a wifi network. Basically am creating a Auto-Login for my university.
Asked
Active
Viewed 2,489 times
3 Answers
3
NetworkInterface[] nics=NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
if (adapter.OperationalStatus == OperationalStatus.Up)
{
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
{
Console.WriteLine("Wifi");
}
}
}
NetworkInterfaceType.Lan works for LAN

Peter Duniho
- 68,759
- 7
- 102
- 136

Yasir Kamal
- 443
- 4
- 10
-
This answer is potentially useful to some, but does not appear to address the actual question being asked here, i.e. to _react_ to changes in the network status. – Peter Duniho Nov 23 '15 at 03:17
2
By far the easiest method is to simply attempt to periodically run the standard auto login procedure, if it works all is well and the user is logged in if it does not then there is no connection. There is little point trying to determine WHY there is no connection unless you are writitng some kind network connectivity diagnostic app.

Ben Robinson
- 21,601
- 5
- 62
- 79
1
I suppose you can have a listener thread which will simply check status of internet connection and raise event if connection appeared or lost.

Alex Krupnov
- 460
- 3
- 8