Check domain name servers with php

Discussion in 'PHP' started by amelen, Jun 11, 2009.

Thread Status:
Not open for further replies.
  1. #1
    Is there a way to check a domains name servers with php? To be more general, we have members submit domain names they want us to host and I want to somehow automatically check if the set the name servers to point to us. Right now it's being done very manually.

    The best I found so far is:

    $domaincheck = checkdnsrr($HTTP_POST_VARS[domain],"ns"); 
    Code (markup):
    but that only checks if the domain exists. I'm looking for a way to not only verify that the domain exists, but to verify that the name servers are what we want them to be. Any ideas?
     
    amelen, Jun 11, 2009 IP
  2. webhed21

    webhed21 Member

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    I haven't had any use for this function so it's new to me, but I'm sure it will prove useful to you

    I dont think i can post links yet so you'll have to copy and paste without the spaces

    http ://us. php. net/dns_get_record
     
    webhed21, Jun 11, 2009 IP
  3. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #3
    Bohra, Jun 11, 2009 IP
  4. amelen

    amelen Active Member

    Messages:
    686
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Thanks to both of you! How would I get that function to just output the name server that I can store in a variable or database?
     
    amelen, Jun 12, 2009 IP
  5. webhed21

    webhed21 Member

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Took me some time to get this worked out.. It's not pretty but it should get you going in the right direction.. as I said this is my first run in with this function.
    
    <?PHP
    $result = dns_get_record("YOURDOMAIN.COM", DNS_ANY, $authns, $addtl);
    
    $count = sizeof($result);
    $i=0;
    $nameserver = array();
    while($i < $count) {
    	$temp_array = $result[$i];
    	
    	if($temp_array['type'] == "NS") { array_push($nameserver, $temp_array ['target']); }
    
    $i++;
    
    }
    $count = sizeof($nameserver);
    $i=0;
    
    while($i < $count) {
           //This is just to show the contents of the nameserver array.
    	print "nameserver[$i]: $nameserver[$i]<br>";
    
    $i++;
    
    }
    
    ?>
    
    PHP:
    That should put all the listed nameservers for the given YOURDOMAIN.COM into an array called $nameserver. You could then compare that with your own. I tested on a few different domains and went with the array because most domains have more than 1 NS record, this should extract them all.

    Hope this helps you out

    Eddie
     
    webhed21, Jun 12, 2009 IP
  6. amelen

    amelen Active Member

    Messages:
    686
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    85
    #6
    Wow.. thanks! I've been trying all day and didn't get as far as you. Thanks!!
     
    amelen, Jun 13, 2009 IP
  7. webhed21

    webhed21 Member

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #7
    glad i could help :D
     
    webhed21, Jun 13, 2009 IP
Thread Status:
Not open for further replies.