Monitor All active connections Windows XP SP2

Mar 4, 2010 at 9:16 AM

Hi All,

I am trying to write an VB.NET application which will monitor all incoming connections on my system. I have been trying to use the the dotras.dll to access these values but the dialer never receives any connections even though I have a modem that has been authenticated on my server. I am using the Raspppoe Driver on my "Accept Incoming Connections" server to authenticate PPPoE sessions.

Is there away to allow this code to monitor all current connections on the system?

 

I have also used the example code and that doesn't find any active connections and there IP addresses either.

 

Any help would be greatly appreciated

 

Boyindie

Coordinator
Mar 4, 2010 at 1:22 PM

Unfortunately what you're asking is server related functionality, not client. At this time the project does not support any of the RAS server API. I want that implemented some day, but right now starting that phase of the project is no where near in sight.

You can try using RasConnectionWatcher, but that also might be only related to client connections.

Sorry :(

Mar 4, 2010 at 1:50 PM

Ok,

Thanks for your feedback, jeff.

I am stuck on a close deadline here and not wanting to have to do a lot of development on this, I was wondering how easy it is to integrate this into VB or C# code

How do I go about actually accessing the API itself, or can that only be done with the use of C++?

 

As the only features I need to use is the ability to disconnect all connections into the server and access the client IP address.

 

boyindie

Coordinator
Mar 4, 2010 at 3:13 PM

From my research on the server APIs, most of them will need to be done with C++. I haven't done much research on the topic, and it's probably been a year since I last looked at them. As far as how difficult they are to implement, if they're anything like the ones I've already done it can be extremely difficult unless you're used to working with p/invoke. Especially when you start talking about struct alignments and supporting multiple operating systems.

If you want to see how to properly expose Win32 APIs from C#, check out the NativeMethods, UnsafeNativeMethods, and SafeNativeMethods classes in this project. Those contain the struct, enum, and API definitions necessary for RAS. Here's a link that might help you understand what each of those 3 classes do: http://msdn.microsoft.com/en-us/library/btadwd4w(VS.80).aspx. As for the interaction between the project and Windows, that is all handled by my RasHelper class.

The APIs you'll be looking for in the Windows SDK should all start with "Ras" in the name, and they should all be defined in the Ras.h header file included in their SDK.

Apr 9, 2010 at 1:10 PM

Hi Folks,

A very big Thank You to Jeff for all his work on behalf of software engineers everywhere !

Like boyindie I need to monitor RAS Connections at the Server end, in my case they will actually be connections made by a separate application also written by me to collect data from remote embedded PC's that are running Embedded XP, hosting the RAS Server.

The reason I need to monitor the connection is because I am using Dial Up connections and these occassionally get broken leaving an orphaned connection at the remote embedded PC that then blocks any further access to that PC.

I was thinking about using RasConnectionWatcher to monitor the incoming calls and check that they were closed in a timely fashion, I was then hoping to be able to kill them if they didn't close within a certain time.  So has anybody tried Jeff's suggestion that the Connection Watcher might work on the server end ?

Does anybody have any suggestions for fixing these orphaned connections or for detecting them and killing them is necessary ?

Thanks in advance

Coordinator
Apr 9, 2010 at 1:52 PM
Edited Apr 9, 2010 at 1:54 PM

You're quite welcome. It's been a lot of fun, and challenging at times. The APIs I have implemented in the project are all client related, they aren't able to notify you what's going on with a RRAS server. What you're looking for to monitor incoming and terminated connections on a server are:

MprAdminAcceptNewConnection: http://msdn.microsoft.com/en-us/library/aa374551(v=VS.85).aspx and MprAdminConnectionHangupNotification: http://msdn.microsoft.com/en-us/library/aa374561(v=VS.85).aspx

Like I've said before, I haven't done any of these yet in the project so you'll need to implement them yourself. Unlike the RasConnectionWatcher, the RRAS server API doesn't have the callback passed to it which is where the problem arises. In their implementation, Windows is the calling the callback once it's been registered on the server which means you're going to need to use C++ to expose the callback function.

Edit: What RAS server are you using and what operating system is hosting it?

Apr 9, 2010 at 2:05 PM

Thanks for the very quick response Jeff.

Unfortunately implementing your suggestion is well beyond my capabilities I'm afraid, so I'm going to have to fall back on a different approach.  I'm going to try monitoring the Comms Port in some non-intrusive fashion and detect the incoming call and use that to start a timer that tries to kill the connection on expiry.

I'm using Windows XP Embedded SP2, (or SP3, I'm afraid I don't know which, it was supplied to me by a third paty), and it's the standard RAS Server that comes with XP, I've not done anything beyond configure it to accept incoming connections with a specific User Name and Password.

The reason that all this is such a problem is that the Embedded PC's won't live in a nice local server room, but out in the middle of nowhere all over the country !  This fairly obviously makes walking up the PC and manually killing the connection a little difficult !

I have been using the standard XP supplied RasDial.exe to make my outgoing phone calls up to now, but I'm about to try and use DotRas instead in the hope that this will improve the reliability of my Data Collector, although it obviously won't improve the reliability of the phone lines, so I'll still have to cope with the problem described above !

Thanks again

Coordinator
Apr 9, 2010 at 2:12 PM

Well I can tell you DotRas can definitely replace using those executables to make outgoing RAS calls. What if you tried changing your implementation so the clients were the ones knowing whether they've become disconnected? You could make use of RasConnectionWatcher in that scenario.

Apr 9, 2010 at 2:33 PM

Hmm ....

Interesting idea, but I don't think it will work, let me explain how I see the issue.

My Data Collector, (the Client), already knows that the connection has been dropped and handles it correctly, (most of the time, but that is what I hope will be fixed by DotRas !), the Embedded PC, running Embedded XP and our VB Data Gathering application in the middle of nowhere, (the Server), is the one that blocks all future incoming calls because of the orphaned RAS connection.  This means that there is ABSOLUTELY no way of recovering the situation short of a VERY expensive site visit with a keyboard monitor and mouse !

Currently in a Lab environment, I can walk over to the Server and manually kill the Connection, that won't be possible once this goes into service.

Thank you for the links you put in your post, they lead me to this link http://msdn.microsoft.com/en-us/library/aa378047(v=VS.85).aspx which looks like it should be very helpful in sorting the problem out on the Server, although I've only glanced at it so far.

Thanks again...

Coordinator
Apr 9, 2010 at 3:12 PM

What if you did some kind of pinging mechanism with your data collection software, that if it your server receive a reply by a client after X number of seconds beyond the expected time it'd cause a timeout that would then disconnect the connection. You could use the MprServerAdminConnect API to get the server handle, use that handle with the MprAdminConnectionEnum to retrieve the list of connections, push the connection handle to MprAdminPortEnum and then get the port handle and push that to MprAdminPortDisconnect. Obviously this is totally speculative, I haven't ever tried working with those functions.

Those APIs all look to be your standard APIs that would not require any C++, but it would take some serious knowledge of C#. If you're unfamilar with implementation of Win32 APIs, take a peek at the UnsafeNativeMethods, SafeNativeMethods, and RasHelper classes in the project. If you're looking at the latest source code, it's going to be a bit more complicated due to the unit testing redesign I've been doing lately, but the concept remains the same. If you installed the source code with the package you downloaded, that would be much easier to read.

Apr 9, 2010 at 3:33 PM

Hi Jeff,

My big problem is that very ocassionally the telephone line connection will be dropped without any intent on the part of either my Data Gathering Outstation or my Data Collecting Instation, this is what orphans the connection at the Outstation, (the Server), but the Instation, (the Client), can't do anything about it at that point other than report the issue, the Server is stuck with no way for the Client to re-connect to it unless without a site visit.

I think that turning your suggestion about the ping around so that once the ping from the Server to the Client FAILS because the connection has been broken, then the server makes sure that any orphaned connection is killed should solve my problem.

That just leaves the problem of getting the RAS Admin API to work, OUCH !

Thanks yet again for your help.

Coordinator
Apr 9, 2010 at 3:45 PM

Well if you have any questions about DotRas, feel free to ask.

Happy coding!

Apr 9, 2010 at 3:52 PM

Thanks Jeff, I'll try very hard to limit my questions in future to DotRas !!  ;-)