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?
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
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
This is an old thread... Very old.. But hope this helps someone..
If My.Computer.Network.Ping("192.168.0.254") Then 'online Else 'offline End If
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.