Jump to content

Recommended Posts

Hi everyone, long time reader, first time poster here. 

 

I've been banging my head against the wall for the past few hours, trying to figure out a ways of knowing (and displaying on a webpage) whether my clients have setup correctly their DNS addresses to my ‘remote’ DNS server or not, instead of using their default DNS server provided by their ISP.

 

The closest I've gotten to answer my question is on this post:

http://forums.phpfreaks.com/topic/282424-nslookup-script-help-needed/

 

$ip = gethostbyname('www.facebook.com');

if ($ip == '46.46.46.46') { //this is the ns after dns filter for facebook.com
    echo "Smart DNS Is Set up ";
} elseif ($ip == '69.171.229.25') { //this is true ns lookup
    echo "Smart DNS Is Not Set UP";
}

 

Seems to me like the OP is trying to achieve the same results I am. Modifying an entry on his DNS server (probably) to point to a different facebook IP address. Here's where the tricky part is in play. Please follow me briefly:

1. I'm pointing www.facebook.com to 46.46.46.46 on my 'remote' dns server.

2. Using the above code, I've uploaded a testdns.php to my 'remote' dns server. 

3. If I use my ISP's DNS server on my PC and do an nslookup on www.facebook.com, I get 69.171.229.25, good. I then switch my PC's DNS server addresses to my 'remote' server address in question, I do another nslookup on www.facebook.com and I get 46.46.46.46. Good. Up to here, everything works as expected.

4. When I try to view this on the uploaded webpage, however, it always resolves to the real facebook address, and get the  "Smart DNS Is Not Set UP" message, no matter whether I use my ISP's DNS addresses (as expected) or my 'remote' DNS server's addresses (here's where it's failing).

5. I'm only using IP4, BTW.

 

I've tried to just echoing the output of

 

$ip = gethostbyname('www.facebook.com');

echo $ip;

 

But no matter what DNS server address I use on my PC, I always get the 'real' address and not the one I'm pointing to on my DNS server. Please do note that if I manually do an nslookup on a cmd prompt on my PC, it resolves correctly; it's only the above code that always resolves to the true address instead of the one I'm pointing on my DNS server.

 

Any help will certainly be much appreciated,

 

Thanks,

Hi everyone, long time reader, first time poster here. 

 

I've been banging my head against the wall for the past few hours, trying to figure out a ways of knowing (and displaying on a webpage) whether my clients have setup correctly their DNS addresses to my ‘remote’ DNS server or not, instead of using their default DNS server provided by their ISP.

 

The closest I've gotten to answer my question is on this post:

http://forums.phpfreaks.com/topic/282424-nslookup-script-help-needed/

 

$ip = gethostbyname('www.facebook.com');

if ($ip == '46.46.46.46') { //this is the ns after dns filter for facebook.com
    echo "Smart DNS Is Set up ";
} elseif ($ip == '69.171.229.25') { //this is true ns lookup
    echo "Smart DNS Is Not Set UP";
}

 

Seems to me like the OP is trying to achieve the same results I am. Modifying an entry on his DNS server (probably) to point to a different facebook IP address. Here's where the tricky part is in play. Please follow me briefly:

1. I'm pointing www.facebook.com to 46.46.46.46 on my 'remote' dns server.

2. Using the above code, I've uploaded a testdns.php to my 'remote' dns server. 

3. If I use my ISP's DNS server on my PC and do an nslookup on www.facebook.com, I get 69.171.229.25, good. I then switch my PC's DNS server addresses to my 'remote' server address in question, I do another nslookup on www.facebook.com and I get 46.46.46.46. Good. Up to here, everything works as expected.

4. When I try to view this on the uploaded webpage, however, it always resolves to the real facebook address, and get the  "Smart DNS Is Not Set UP" message, no matter whether I use my ISP's DNS addresses (as expected) or my 'remote' DNS server's addresses (here's where it's failing).

5. I'm only using IP4, BTW.

 

I've tried to just echoing the output of

 

$ip = gethostbyname('www.facebook.com');

echo $ip;

 

But no matter what DNS server address I use on my PC, I always get the 'real' address and not the one I'm pointing to on my DNS server. Please do note that if I manually do an nslookup on a cmd prompt on my PC, it resolves correctly; it's only the above code that always resolves to the true address instead of the one I'm pointing on my DNS server.

 

Any help will certainly be much appreciated,

 

Thanks,

 

Link to comment
https://forums.phpfreaks.com/topic/282847-nslookup-script-redux/
Share on other sites

Anything you do on the server end is going to use your server's DNS settings, not the client's.

 

What you'd need to do is use Javascript to make a request for some domain which would only resolve with your custom dns. Have a simple webserver running for that domain to serve up a JS file or image or something. For example, you could serve up a JS file like:

document.getElementById('results').innerHTML = 'Success!';
clearTimeout(timer);
Then in your test page do something like:

<div id="results">Testing...</div>
<script type="text/javascript">
var timer = setTimeout(function(){
    document.getElementById('results').innerHTML = 'Failed!';
}, 6000);
</script>
<script type="text/javascript" src="http://test.fakedomain/test.js"></script>
That will show a Testing message to the user, and set a timer so that after 6 seconds it will consider the request failed and show that. If the DNS is setup correctly, then test.fakedomain will resolve and the above script will run changing the message to Success and canceling the timer.

Thanks so much for the reply, kicken.

The following quote is definitely an eye opener:

 

 

Anything you do on the server end is going to use your server's DNS settings, not the client's.

 

I guess can stop wasting my time following the previous OP's idea an work on some client side JS. 

 

If you don't mind elaborating a bit more on your approach. My idea was to use Dnsmasq to resolve a given domain, i.e. fasebuk.com (LOL) to 46.46.46.46. For obvious reasons, however, I have no access to that server, so I have no means to  upload a JS file. Will a dormant domain I have at GoDaddy do it? And just point to if 'from my custom dns resolve only' deleting all its A records at Godaddy so no other DNS server can resolve to it?

Sorry about the newbiness, but I must admit that my coding knowledge are quite poor,

 

Thanks again,

Hey Jazzman, thanks for the reply. Yes, I understand that they do a lot of load balancing, specially if you log from different regions. Going back to the previous reply by kicken, however, wouldn't we still face the same problem that any webpage code would be run server side?

DNS technology allows you to type names into your Web browser and dns (server) try to find out the nearest target server with this domain name.

So, what do you want to achieve? To get the closest facebook IP address according to GoDaddy remote server or according to the client ip address at this moment?  

Can you tell us the whole story?

Edited by jazzman1

Hey Jazzman, thanks for the reply. The whole story is on my original post above.

 

In case I wasn't clear (sorry, English is my third language!) I'm trying to find an easy way to let the users of my DNS server know whether they have changed their DNS settings correctly, Ideally, after they change their DNS settings on their PC, they could click a link and know right away whether they are using my DNS server or still using their ISP's. Something like this comes to mind http://news.cnet.com/8301-13554_3-10025202-33.html. In case they aren't, then I can redirect them to a help page, where I can show them how to flush their DNS cache, browser cookies, etc.

 

Thanks!

I don't know Jamie0, whether is there a possible way to check which DNS server the client use. Maybe, it's possible with javascritp to force a ping from the client browser to the remote host and then to compare this ip address to that one on your server ....but I don't really sure about that.

Thanks anyways, Jazzman.

 

I was originally thinking (as per my previous post) to forward a domain on my DNS server into a fake IP address, and then let the client click on that link. Two scenarios will happen. "If the client reaches the 'real' address" then he is still using his ISP's DNS. "If he gets forwarded to the fake IP address", I can be sure he is using my DNS server as a resolver. Problem seems to be, as per kicken's post above, that no matter what, the DNS resolve will be done at the server's end...

 

I'm not double guessing kicken, but, just but, how or when does a client actually uses his own DNS settings? I mean, if I click on an URL on a webpage, isn't that the equivalent of me typing that address into my browser, hence using whatever DNS server I have set up on my end? Just thinking aloud...

I mean, if I click on an URL on a webpage, isn't that the equivalent of me typing that address into my browser, hence using whatever DNS server I have set up on my end? Just thinking aloud...

Yes, if you click a link then your browser resolve the domain using it's DNS settings. This is basically what I suggested to you, include a JS file which will show a success message if the browser successfully resolves the domain and loads it. Your original post was about having PHP try and check the DNS which means it would be using the server's DNS not the clients.

 

The OpenDNS Test Page does something similar, but more sophisticated from what I can tell. They have two IP's that map to the www.opendns.com domain (xx.218 and xx.219). The xx.218 IP seems to be the IP they publish to the global internet, while the xx.219 IP is published by their DNS system. On the server end they can check which IP a user connected to and use that to determine if they configured their settings properly or not.

 

Will a dormant domain I have at GoDaddy do it? And just point to if 'from my custom dns resolve only' deleting all its A records at Godaddy so no other DNS server can resolve to it?

You don't even need a registered domain to do the JS test I was talking about. You'd just setup your DNS server with a zone for some special domain, such as test.fakedomain and have it resolve to an IP. You can configure your DNS servers to respond to any domain, there is no need for them be registered or even use one of the established TLDs.

 

You don't even need a registered domain to do the JS test I was talking about. You'd just setup your DNS server with a zone for some special domain, such as test.fakedomain and have it resolve to an IP. You can configure your DNS servers to respond to any domain, there is no need for them be registered or even use one of the established TLDs.

 

There is no way to force his clients automaticaly to use GoDaddy DNS, before to have an agreement with their ISPs. They should create new records for this specific group of users using a remote server. That has benefits for both sides, less data traffic, good performance. That was before when I had a dedicated server, I think nothing changed nowadays.

Anyways.....his question is different here :)

Edited by jazzman1

Hey, Kicken, thanks very much for your help. Much appreciated. Seems like I may be getting there...

This is what I've done so far:

 

1.       On my DNS server, I’ve created a zone file that maps ‘test.fakedomain’ to my DNS server’s address (address=/test.fakedomain/66.76.76.11)

 

2.       I’ve changed my network adapter’s DNS IP to 66.76.76.11

 

3.       To test whether I’m using my DNS server’s resolves, I’ve nslookup’d and pinged ‘test.fakedomain’. Both results are as expected:

C:\Users\test_user>nslookup test.fakedomain
Server:  my.dns.server
Address: 66.76.76.11

Name:    test.fakedomain
Address: 66.76.76.11 

C:\Users\test_user>ping test.fakedomain
Pinging test.fakedomain [66.76.76.11] with 32 bytes of data:
Reply from 66.76.76.11: bytes=32 time=145ms TTL=50
Blah blah blah…

4.       I’m serving ‘dnstest.php’ via Apache from my default site

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1 transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<div id="results">Testing...</div>
<script type="text/javascript">
var timer = setTimeout(function(){
    document.getElementById('results').innerHTML = 'Failed!';
}, 6000);
</script>
<script type="text/javascript" src="http://test.fakedomain/test.js"></script>
<body>
</body>
</html>

5.       And on the same directory, I have ‘test.js’

// JavaScript Document      
       document.getElementById('results').innerHTML = 'Success!';
clearTimeout(timer);

6.       On my browser, I go to http://66.76.76.11/dnstest.php and I get the ‘Testing…’ message for 6 seconds, then it turns into ‘Failed’ when I should get the ‘Success’ message…
 

7.       BTW, pointing my browser to http://66.76.76.11/test.js apache shows the raw code 

 

Do note that for the sake of privacy, I've changed the server's address. Could you please tell me what am I doing wrong?

Edited by Jamie0
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.