3

I check wether a site site is up-and-running by checking for a HTTP 200 status code:

<?php
$url = 'www.proxyserver-demo.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode)
    {
    echo "All's well";
    }
else
    {
    echo "not so much";
    }
?>

Every site I try however, even non-existing ones return 200 OK status without fail, which should not be possible in the case of the non-existing ones. (my code always outputs "All's well")

My OS is Centos linux, what could be the matter here?

5
  • 3
    You can find your answer in this stack overflow post : stackoverflow.com/questions/6541785/…
    – shawty
    Jun 15, 2012 at 12:42
  • Into which concrete problem do you run with your code? It looks like that the actual question is missing.
    – hakre
    Jun 15, 2012 at 13:24
  • The problem is that if a non available url is entered then the dns server redirects the url to opendns.com and i think this is my problem. how to solve this???? And gow to avoid redirection when using curl??? Jun 18, 2012 at 8:11
  • Your CURL_OPT_FOLLOW_LOCATION should be set to false if you wish to ignore redirects. It will not save you from 'injected' severs though since that's not a redirect but a blatantly falsified DNS response. Jun 18, 2012 at 23:39
  • thnxx got it.. and i changed CURL_OPT_FOLLOW_LOCATION as 0 and i got the answer Jun 19, 2012 at 6:17

1 Answer 1

7

sorry for abusing the answer field for what should probably be a comment but I can't really think of a way to present this info properly otherwise. I honestly don't know yet how to whip them comments into any properly displayed and formatted shape. :-|

Anyway, since your code should be working fine but for you it always retuns "everything OK" while you check for a HTTP response, it could be that your ISP is doing DNS-highjacking, which basically is returning fake ip-address data, redirecting you to their own server, usually for monetary gains under the guise of userfriendlyness. (ISP-page that shows "this page doesn't exist" combined with ads or the offer of services such as domain registration, etc..)

an easy way to test is just to ask for DNS data with an application like dig. A query to a properly functioning DNS server for a non-existing domain should return NXDOMAIN as its status:

so when we check for a totally fake domain notexisting.fake with the following command: dig A notexisting.fake., this is what it generally should give:

harald@Midians_Gate:~$ dig A notexisting.fake.

; <<>> DiG 9.7.3 <<>> A notexisting.fake.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 28725
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;notexisting.fake.              IN      A

;; AUTHORITY SECTION:
.                       1780    IN      SOA     a.root-servers.net. nstld.verisign-grs.com. 2012061700 1800 900 604800 86400

;; Query time: 24 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Jun 17 18:05:10 2012
;; MSG SIZE  rcvd: 109

as you can see,asking for this nonexisting domain notexisting.fake. returns us

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 28725

Whereas when we query for google.com, with dig A google.com.

harald@Midians_Gate:~$ dig A google.com.

; <<>> DiG 9.7.3 <<>> A google.com.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13223
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             300     IN      A       74.125.132.138
google.com.             300     IN      A       74.125.132.139
google.com.             300     IN      A       74.125.132.101
google.com.             300     IN      A       74.125.132.113
google.com.             300     IN      A       74.125.132.100
google.com.             300     IN      A       74.125.132.102

;; Query time: 29 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Jun 17 18:05:20 2012
;; MSG SIZE  rcvd: 124

our query returns us the proper NOERROR

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13223
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0

and returns us the ip address found for the A record

;; ANSWER SECTION:
google.com.             300     IN      A       74.125.132.138
google.com.             300     IN      A       74.125.132.139
google.com.             300     IN      A       74.125.132.101
google.com.             300     IN      A       74.125.132.113
google.com.             300     IN      A       74.125.132.100
google.com.             300     IN      A       74.125.132.102

So if your query for the fake domain returns an ip address then you know the problem is with your DNS and your isp no doubt redirects every non-existing request to a server of their own, messing with your 'is my site up strategy' since you'll get a 200 OK status but it'll effectively be from an imposter.

If this is the case then you can only:

  • change your DNS server: use Google Public DNS (8.8.8.8 and 8.8.4.4) or opendns (208.67.222.222 and 208.67.220.220)
  • plead/complain with your isp for them to change this policy or to supply you with your own non-redirecting DNS server
  • run your own private DNS server for your personal lookups if allowed on your network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.