|
-
Mar 24th, 2010, 11:59 AM
#1
Internet Connectivity - Ping-then-do
The attached project has code (MonitorNetworkResource) that can be used to:
- Monitor devices on your network
- Monitor Internet connectivity - it does differently than other tools.
As you may or may not know I think pinging "something" to determine whether or not to do "something" is wrong. An example would be ping a mail server, if the ping is good then send the mail. At best it is based on a naive assumption. If you want to discuss it or have an example of when it is better, I'll be glad to. (see Post #3 this Thread) The complex example shows most of the features of MonitorNetworkResource , though it is unlikely anyone would use them all at once. MonitorNetworkResource was created for developers and should be used as an alternative to ping-then-do.
Here is a simplified drawing of what the internet looks like.

When you ping some far distant host, say www.yahoo.com, and get successful replies the internet is up. When unsuccessful is it Yahoo, your ISP, or some other ISP along the route that is down? Regardless of which, the network is down as far as you are concerned.
More importantly do you care if it is beyond your ISP? You can't do anything about it! I think what most of us really want is to know that we can get to our ISP.
The code references the “edge”. It is the point believed to be where you encounter the internet. In the picture these edges are shown as red dots. (note: PP = peering point) I am the PC attached to RadioWire, and my link IS WIFI, and in reality I am several radio links further away than denoted, which is why my Miles to Edge is off(I use 90% of C for the calculation).
The code determines where the “edge” of the internet is by initially doing a series of pings and checking the IP address of the reply(I am using the same mechanism as trace route).
The “edge” is found when the reply address is not:
On your network
A private IP address (RFC 1918)
Exceptions:
- if the device is on your network and replies successfully, which is why this can be used to monitor devices on your net
- if the reply address is automatic private (169.x.x.x).
From that point on a ping is sent to the “edge” periodically. If you can get to the "edge", then your internet connection is deemed to be up.
I have used similar code in place of pinging some site on the web for a long time. The code contains the accumulation of all that I have learned. Here is a screen shot of the complex sample application. I have simulated a network outage by disconnecting the wire between my Router and the ISP.

A good test of the sample app is:
1 - Start the application
2 – While the app is running repair your network connection if you have a DHCP assigned address, or disable / enable your network interface.
You should see several transitions in the app.
So give it a try, let me know what you think.
Current Code
MonitorNetworkResource dll source always here - Needed for all of the sample applications.
DBStuff.zip
Simple Sample Application always here
BasicMonitor.zip
Complex Sample Application always here
ToPingOrNot.zip
Note - Do not hook NetworkAvailabilityChanged (one of the events available in MyApplication Events). This event is hooked by MonitorNetworkResource. You can gain access to this event by handling NetStateChange which is raised by MonitorNetworkResource.
Note: Do not use this code in commercial products without my permission.
Update Info - check back often
Updated - 27 Mar 2010 @ 1220 CST - uncovered error thanks to Frank L Smith @ MSDN Visual Basic Forum. Initial hop errors cause down indication. Code now keeps hopping until it reaches a max of 5. Situations like this
Code:
1 <1 ms 4294967283 ms 4294967283 ms 192.168.1.1
2 * * * Request timed out.
3 4294967290 ms 4294967292 ms 4294967292 ms 68.86.151.181
4 8 ms 40 ms 8 ms 68.85.174.89
5 4294967292 ms 4294967292 ms 4294967293 ms 68.85.174.85
should now work.
Updated - 29 Mar 2010 @ 1902 CST - Post #6 has list of available methods / properties.
Updated - 30 Mar 2010 @ 0713 CST - Because there are three demo app's now I became tired of copy / pasting MonitorNetworkResource. MonitorNetworkResource has been moved to a .dll project and will have to be built separately. The reference in the demos will need to be changed to where you create your version of the dll
Updated - 31 Mar 2010 @ 1148 CST - Last night I added another router to my test net. In the process I found out that, IMHO, they do not process ICMP packets exactly correctly. I think I'll just leave it at that. The DLL was updated to handle the situation.
Last edited by dbasnett; Mar 31st, 2010 at 11:54 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|