Results 1 to 3 of 3

Thread: How To Query Domain Registration

  1. #1
    Join Date
    Jun 2005
    Location
    Scotland
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How To Query Domain Registration

    I'm not sure if this is the right forum so I'll apologise in advance.

    I'm sure we've all seen the facility to check if a desired domain name is already registered.

    Does any one know how I go about providing that facility on my website or is this type of service only available to ISPs? I'm specifically wanting my site visitors to check for the existance of .uk domains which are handled by Nominet

    Thanks in advance

    Alistair

  2. #2
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Try this HTML/PHP hybrid page:
    PHP Code:
    <html>
    <head>
    <title>PHP WHOIS</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form name="form1" method="post" action="test.php">
    <p>Enter Domain:
    <input name="domain" type="text" id="domain">
    </p>
    <p>
    <input type="submit" name="Submit" value="Check Whois">
    </p>
    </form>
    <?php
    if(strlen($_POST['domain']) > 0){

    // Create Whois Server Array
    $server['nic'] = "whois.nic.uk:No match for";
    $server['crsnic'] = "whois.crsnic.net:No match for";

    // Create Extension Array
    $domainInfo['.co.uk'] = "nic";
    $domainInfo['.org.uk'] = "nic";
    $domainInfo['.ltd.uk'] = "nic";
    $domainInfo['.plc.uk'] = "nic";
    $domainInfo['.com'] = "crsnic";
    $domainInfo['.net'] = "crsnic";
    $domainInfo['.org'] = "crsnic";

    // Separate Domain and Extension
    $fullDomain $_POST['domain'];
    $parts explode(".",$fullDomain);
    $domain $parts[0];
    $extension str_replace($domain,"",$fullDomain);

    // Find Whois Server and Text to Match
    $tempServer $domainInfo[$extension];
    $whoisDetails $server[$tempServer];
    $splitWhois explode(":",$whoisDetails);
    $whoisServer $splitWhois[0];
    $textToMatch $splitWhois[1];

    // Query WHOIS Server for Domain
    $port 43;
    $domainName $domain $extension "\n";
    $fp fsockopen($whoisServer,43);
    fputs($fp$domainName);
    while (!
    feof($fp))
    $whoisRecord .= fgets($fp,128);
    fclose($fp);
    $whoisRecord str_replace("\n","<br>",$whoisRecord);

    // Check Whether Domain is Registered or not
    if(strstr($whoisRecord$textToMatch) != FALSE){
    $registered 0;
    } else {
    $registered 1;
    }

    // Output Results
    if($registered==0){
    echo 
    $domain $extension " is not registered.";
    } else {
    echo 
    $domain $extension " is registered. WHOIS Details:";
    echo 
    "<br><br>";
    echo 
    $whoisRecord;
    }
    }
    ?>
    </body>
    </html>
    Example at http://b3ta.cr3ation.co.uk/images/test.php

    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by AlistairH
    I'm not sure if this is the right forum so I'll apologise in advance.
    The Other forum would probably have been more appropriate as this is predominately a generic server-side programming question.

    Does any one know how I go about providing that [domain name queries] on my website or is this type of service only available to ISPs?
    You would have to use a registrar's WHOIS service, but you certainly can provide your own query interface. However, parsing the output may not be that simple as I don't think there any guidelines on what exactly is stored, and how it should be returned.

    Sending a query is very simple: connect to the WHOIS server on port 43, send the query (with optional flags), followed by a carriage return, line feed (CRLF) pair. You should expect the connection to be automatically closed.

    You can read more in RFC 954. You'll probably want to just focus on the "Command Lines and Replies" section, as I've just covered the protocol (it really is that simple).

    I'm specifically wanting my site visitors to check for the existance of .uk domains which are handled by Nominet
    Then you'll want to use whois.nic.uk.

    Note: You must get permission from Nominet before you start using their WHOIS service for more than the occasional lookup. See their disclaimer for a bit more information.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •