Check specific network status repetely

Feb 2, 2011 at 6:43 PM

Hello everybody.

 

I'm working in a developement of open source .net VPN client. Could you help me to create a cyclic verification of status of an specific windows connection? For example: I have an windows VPN connection called "CustomVPN". I need (with a timer object in VB.net) to check the status (connected or disconnected) of this connection without use ping command. Any ideas to do this?

Since now, Thanks!

 

Eduardo.

Coordinator
Feb 2, 2011 at 9:45 PM

You don't need to use a timer either, the RasConnectionWatcher class subscribes to events from Windows when the connection is lost. It'll raise an event when connections are made or lost.

Dim watcher As New RasConnectionWatcher
AddHandler watcher.Disconnected, Me.watcher_Disconnected
watcher.EnableRaisingEvents = True

Private Sub watcher_Disconnected(ByVal sender As Object, ByVal e As RasConnectionEventArgs)
    ' A connection has disconnected.
End Sub

You can check the SDK for examples as well as documentation on the class.

Feb 3, 2011 at 12:49 PM

Hello Jeff!

 

Thank you very much for the answer!

With this logic above, we can't correlate the handler with a specific network connection, right?

I'm going to try this now and on later I post a reply with results.

 

Best regards,

Eduardo.

Coordinator
Feb 3, 2011 at 3:00 PM

You can, that was merely a basic example how to get the class working. The RasHandle returned by the Dial or DialAsync method from RasDialer along with the Handle property on RasConnection can all be used to set the Handle property on the RasConnectionWatcher to receive notifications about that specific connection. However, if the connection is disconnected you will need to change the handle to the new handle once the connection is redialed as the previous handle will no longer be valid. Also, the Connected event raised by the component is raised for all connections on the machine, the Handle property on RasConnectionWatcher does not modify the behavior of this event.

The Disconnected, BandwidthAdded, and BandwidthRemoved events are all affected.