views:

1110

answers:

10

Im getting frustrated because of OpenDNS and other services (ie: roadrunner) that now always returns a ping even if you type any invalid url ie: lkjsdaflkjdsjf.com --- I had created software for my own use that would ping a url to verify if the site was up or not. This no longer works. Does anyone have any ideas about this?

Requirements: 1.) It should work with any valid web site, even ones i dont control 2.) It should be able to run from any network that has internet access

I would greatly appreciate to hear how others now handle this.

Thank you greatly :-)

I would like to add, im attempting to do this using System.Net in c#

new addition: Looking for a solution that i can either buy and run on my windows machine, or program in c#. :-)

update: update: update: update: Thank you all very much for your answers. Ultimately i ended up creating a solution by doing this: 1.) Creating a simple webclient that downloaed the specified page from the url (may change to just headers or use this to notify of page changes) 2.) Read in xml file that simply lists the full url to the site/pages to check 3.) Created a windows service to host the solution so it would recover server restarts. 4.) On error an email and text message is sent to defined list of recipients 5.) Most values (interval, smtp, to, from, etc) are defined in the .config for easy change

I will be taking some of your advice to add 'features' to this later, which includes: - AJAX page for real-time monitoring. I will use WCF to connect to the existing windows service from the asp.net page - Download Headers only (with option for page change comparison) - make more configurable (ie: retries on failure before notification)

+3  A: 

Wget is a nice alternative. It will check not only whether the machine is active, but also whether the HTTP server is accepting connections.

Sherm Pendley
Andrew Edgecombe
+2  A: 

To see if a service is up, not only should you ping, but it's good to have scripts that will hit a service, such as a website, and get back a valid response. I've used What's Up Gold in the past, rather than write my own. I like all the features in products like that. such as sending me a page when a service is down.

stephenbayer
A: 

I've found ping to be very unreliable just because of all the hops you're having to jump through, and something in between can always interfere.

Trying to open up an http connection with a web server is probably the best way to go.

Jeff Schumacher
+1  A: 

You could create a simple web page with an address bar for the website and some javascript that uses AJAX to hit a site. If you get any HTTP response other than 200 on the async callback, the site isn't working.

<html>
  <head>
     <script language="javascript" type="text/javascript">
     <!--
        var ajax = new XMLHttpRequest();

        function pingSite() {
           ajax.onreadystatechange = stateChanged;
           ajax.open('GET', document.getElementById('siteToCheck').value, true);
           ajax.send(null);
        }

        function stateChanged() {
           if (ajax.readyState == 4) {
              if (ajax.status == 200) {
                 document.getElementById('statusLabel').innerHTML = "Success!";
              }
              else {
                 document.getElementById('statusLabel').innerHTML = "Failure!";
              }
           }
        }
     -->
     </script>
  </head>

  <body>
     Site To Check:<br />
     <input type="text" id="siteToCheck" /><input type="button" onclick="javascript:pingSite()" />

     <p>
        <span id="statusLabel"></span>
     </p>
  </body>

This code depends on the browser not being IE and I haven't tested it, but it should give you a really good idea.

IAmCodeMonkey
This is an interesting idea. How would i 'hit' a website with it though? ie: would i load the site in the browser. Would the fact that my internet providers site come up (road runner) still work? Do you have any code sample you could provide. Thank you very much for your response :-)
schmoopy
Added a code sample for you.
IAmCodeMonkey
Thank you for the code sample. I will give this a try :-)
schmoopy
A: 

You could try running 'httping' if you have cygwin available or

http://freshmeat.net/projects/httping/

dr_pepper
+1  A: 

For the record, lkjsdaflkjdsjf.com is a hostname (which at the moment is not registered to anyone). ping does not work with URLs, ping works with hostnames. hostnames are looked up using the Domain Name System. DNS is supposed to fail when hostnames are not registered.

The problem is that some services (apparently your ISP, and definitely OpenDNS) do NOT fail DNS requests for hostnames that aren't registered. Instead they return the IP address of a host on their network that presents a search page to any http request.

You appear to want to know two things: Is the name real (that is, is there a host with this name registered to some actual machine)? and Is that machine functioning?

If you already know that the name in question is real (for instance, you want to know if www.google.com is up), then you can use ping because you know that the name will resolve to a real address (the ISP can't return their IP for a registered name) and you'll only be measuring whether that machine is in operation.

If you don't know whether the name is real, then the problem is harder because your ISP is returning false data to your DNS request. The ONLY solution here is to find a DNS server that is not going to lie to you about unresolved names.

The only way I can think of to differentiate between your ISP's fake records and real ones is to do a reverse lookup on the IP you get back and see if that IP is in your ISP's network. The problem with this trick is that if the ISP doesn't have reverse DNS info for that IP, you won't know whether it's the ISP or just some knucklehead who didn't configure his DNS properly (I've made that mistake many times in the past).

I'm sure there are other techniques, but the fact that DNS lies underneath everything makes it hard to deal with this problem.

Michael Kohne
Very well put. I have however ping'd a real domain name, then stopped the web server, pinged it - and it returned open DNS's ip. I may try reverse as an added feature, but maybe i should use the domain name and IP address. If ping returns a different IP i know its invalid.. hmmm
schmoopy
That's really...wrong. OpenDNS CAN'T be returning their IP just because your web server is down, it would kill the entire net. Are you sure you didn't take out your name server as well as the web server?
Michael Kohne
A: 

As far as I can see, the problem here that OpenDNS resolves invalid domains back to themselves to forward you on to something close to what you're after (so if you typo ggooggllee.com you end up at the right place via a bounce from the OpenDNS servers). (correct me if I'm wrong)

If that's the case, you should just be able to check whether the IP you've resolved == any of the IPs of OpenDNS? No more ping - no protocol (HTTP) level stuff - just checking for the exceptional case?

Martin
A: 

If you tend toward the sys-admin solution rather than the programming solution you could install a local name server and tell it not to accept anything but NS records for delegation only zones. This was the fix I (and I assumed everyone else on the internet) used when Network Solution/Verisign broke this last time. I installed BIND on a couple of local machine, told my DHCP servers to hand out those addrs as the local name servers, and set up something like the following for each of the delegation only zones that I cared about:

zone "com" { type delegation-only; };
zone "net" { type delegation-only; };

Come to think of this, I think this might be turned on by default in later BIND versions. As an added bonus you tend to get more stable DNS resolution than most ISPs provide, you control your own cache, a little patching and you don't have to rely on your ISP to fix the latest DNS attack, etc.

jj33
A: 

Don't directly know of any off the shelf options in c#, although I'd be very suprised if there aren't a few available.

I wrote something similar a few years ago, don't have the code anymore cos it belongs to someone else, but the basic idea was using a WebClient to hit the domain default page, and check for a http status code of 200.

You can then wire any notification logic around the success or fail of this operation.

If bandwidth is a concern you can trim it back to just use a HEAD request.

For more complex sites that you control, you can wire up a health monitoring page that does some more in depth testing before it sends the response, eg is DB connection up etc.

Often a machine that is dead on port 80 will still respond to a ping, so testing port 80 (or whatever other one you are interested in) will be a much more reliable way to go.

seanb
A: 

i like CALM for this sort of thing as it logs to a database and provides email notifications as well as a status dashboard

you can set up a test page on the site and periodically do a GET on it to receive either a 'true' result (all is well) or an error message result that gets emailed to you

caveat: i am the author of CALM

Steven A. Lowe