Link to home
Start Free TrialLog in
Avatar of BedouinDN
BedouinDN

asked on

Detect network connection state changes using SENS or other method

Hi guys.

I have been asked to create an application that will detect network connection state changes in any of the network adapters (Wireless, LAN, RAS etc) and then perform a task depending on which type of adapter is enabled and connected at the time.

So I am completely lost and have no idea where to start.. :-(

I have managed to find an interface which has routines that look sort of like what I am after however have no idea on how to use/implement them.

Does anyone know how to detect network state changes and identify the connected interface when the state changes??

Have put 250 points down so far and will raise as appropriate as things get more in depth.

Looking for suggestions and/or sample code on how to use SENS to do this (if it can) or suggestions on other alternative methods.

Regards.
Colin..
Avatar of Russell Libby
Russell Libby
Flag of United States of America image


Colin,

Your question is a little confusing...

Determining the adapter/interface state is not a problem, as the ip helper library can be used to determine current states, etc. But regarding "which" adapter is connected? You do realize that they ALL could be connected, right? And I am really not sure what you mean by "enabled"? Perhaps with some details, myself or others could assist further.

Regards,
Russell
Avatar of BedouinDN
BedouinDN

ASKER

Hi there.
Thanks for your reply..

Basically, what I have been asked to do is have an application running (more than likely running as a service) that will detect when a network adapter (RAS, LAN or otherwise) has connected to any network, then disable/disconnect all other adapters on the machine, if more than one adapter is connected to a network, I will disable/disconnect all other adapters other than the LAN adapter.

The premise is to ensure security on the network so that no machines will be connected to the LAN that have a connection to the outside world on any other adapter. This will need to include things such as wireless adpaters etc.

To make it easier for the user to enable the other adapters (when at home or otherwise away from the network), I would need to be able to provide a simple right click enable option for each adapter found on the machine or perhaps enable all adapters found if no network connection is found.

Thanks again..
Colin.

Thanks for the explanation.... it all makes sense except for one part. HOW do you plan on disabling all the other adapters? I only ask because this was not mentioned as part of the original question.

Russell


Gotta tell you.. Have no idea as yet, I only really mentioned it here so that I could explain what I am trying to do.

It is relativly simple to right click on a network connection (rather than the adapter) to disable so maybe I should start there looking for the API to perform that instead...

I don't think that there is really any need to diable the adapter itself, only really need to stop other adapters from having an enabled connection.

Colin..

Hmmmm....

The SetIfEntry is the only api that I am aware of for disabling the adapter/interface. While it does "work", in the aspect of stopping traffic, it does some quirky stuff as well, and does not appear to be the same thing that is performed when the connection is right click | Disable 'd.

I will research into this for you, but am not promising anything.

Russell
Thanks Russell,
With the detection of current state of all adapters, would this be done using a timer object to call the function from IPHLPAPI, or is there an interface that would send a notification event on state change?

It would be your choice. A timer event could be used, and should be sufficient for what you are doing, or you could use the notification events, which require the use of threads. (They don't always fire correctly either <g>)
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Russell.. You are a dead set legend.

Rather than get me started you have basically given me everything I need to knock up this application in a couple of days.

It took me 5 minutes to install the component and and compile the sample app and not a single issue, the enable and disable functions are exactly what I need and the state changes are detected beautifully.

Can you please make a post in this thread -> https://www.experts-exchange.com/questions/21241053/Detect-Network-Connection-State-Changes.html
as there is another 500 points there for you as well.

Thanks again mate..
Colin.

Colin,

You humble me with your comments.... I'm just glad the code works as you were expecting. Should you run into problems/issues, let me know and I will be happy to assist.

Kind regards and happy holidays,
Russell