views:

27

answers:

2

Hi!

A new client has recently asked me to develop a Windows service that will monitor whether or not his server has internet connectivity. The service should log when the connection goes down to Local Only and back up to Internet Access as shown in Network and Sharing Center.

My original idea was to have the service ping a website like google every 5 minutes or so, but I don't know how to retrieve the results of the ping, so I then thought I could code a WebBrowser control into it and write the log entries based on the results of connection attempts from that.

This also seems like a rather impractical idea though, so can anyone suggest the best way to go about this?

+1  A: 

Since you are working in windows, this is what you can try. http://www.go4expert.com/forums/showthread.php?t=2557

For linux a simple bach script will do the job.

#!/bin/bash
WGET="/usr/bin/wget"

$WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null
if [ ! -s /tmp/index.google ];then
echo "no"
else
echo "yes"
fi
Tushar Tarkas
A: 

Take a look at this answer, this and...

Probably you may use WinAPI funcs InternetGetConnectedState and InternetCheckConnection

Correct declarations of them you can find at pinvoke.net

Eugene Cheverda