Edwin V.

  • Home
  • Over Edwin V.
    • Edit
    • Delete
    • Tags
    • Autopost

    Whois script

    De onderstaande klasse voor PHP 5 kan gebruikt worden om een whois query uit te voeren. Hiermee kan je controleren of een domeinnaam beschikbaar is. Er wordt gebruik gemaakt van de ‘whois is’ methode bij .nl domeinen, zodat het limiet van 15 aanvragen per dag omzeilt wordt.

    <?php

    /**
    * Whois class
    * Copyright by Edwin Vlieg - Flydesign.nl
    *
    * Example use:

    $who = new whois();
    $result = $who->checkDomain("flydesign", "nl");

    if($result == Whois::AVAILABLE){
    echo "Domain available";
    } else {
    echo "Domain not available";
    }

    *
    */

    class Whois
    {

    const AVAILABLE = 1;
    const TAKEN = 2;
    const NO_EXTENSION = 3;
    const NO_SERVER = 4;
    const ERROR = 5;
    const NO_DATA = 6;
    const INVALID_NAME = 7;

    private $aExtensions;
    private $sExecCode;
    private $iPort;
    private $sResult;

    /**
    * @desc Create a new whois instance
    */
    function __construct(){
    $this->iPort = 43;

    /**
    * Extension array
    * Insert new sExtensions in this array, to make more sExtensions available for check
    */
    $this->aExtensions = array(
    'nl' => array('whois.domain-registry.nl', 'is free'),
    'com' => array('whois.crsnic.net', 'No match for'),
    'net' => array('whois.crsnic.net', 'No match for'),
    'org' => array('whois.publicinterestregistry.net', 'NOT FOUND'),
    'co.uk' => array('whois.nic.uk', 'No match'),
    'edu' => array('whois.internic.net', 'No match'),
    'be' => array('whois.dns.be', 'No such domain'),
    'cc' => array('whois.nic.cc', 'No match'),
    'ac.cn' => array('whois.cnnic.net.cn', 'no matching record'),
    'de' => array('whois.nic.de', 'No entries found'),
    'dk' => array('whois.dk-hostmaster.dk', 'No entries found'),
    'fr' => array('whois.nic.fr', 'No entries found'),
    'it' => array('whois.nic.it', 'No entries found'),
    'pl' => array('whois.dns.pl', 'does not exists'),
    'se' => array('whois.nic-se.se', 'No data found'),
    'info' => array('whois.afilias.net', 'NOT FOUND'),
    'biz' => array('whois.nic.biz', 'Not found'),
    'ws' => array('whois.nic.ws', 'No match for'),
    'gov' => array('whois.nic.gov', 'No match for'),
    'tv' => array('whois.internic.net', 'No match for'),
    'name' => array('whois.nic.name', 'No match'),
    'pro' => array('whois.internic.net', 'No match for'),
    'ie' => array('whois.domainregistry.ie', '% There was no match in the IE Domain'),
    'us' => array('whois.nic.us', 'Not found:'),
    'tk' => array('whois.dot.tk', 'not known'),
    'cd' => array('whois.cd', 'No match'),
    'aero' => array('whois.information.aero', 'is not registered'),
    'gr' => array('whois.ripe.net', 'No entries found'),
    'by' => array('whois.ripe.net', 'No entries found'),
    'ad' => array('whois.ripe.net', 'No entries found'),
    'lv' => array('whois.ripe.net', 'No entries found'),
    'eu.lv' => array('whois.biz', 'Not found'),
    'bz' => array('mhpwhois1.verisign-grs.net', 'No match'),
    'es' => array('whois.ripe.net', 'no entries found'),
    'jp' => array('whois.nic.ad.jp', 'No match!!'),
    'cl' => array('whois.nic.cl', 'no existe'),
    'ag' => array('whois.nic.ag', 'NOT FOUND'),

    );
    }

    /**
    * @desc Add a new sExtension to the array (will only apply on the current object)
    * @param string $sExtension Name for the sExtension
    * @param string $sServer Server for whois data
    * @param string $sFreeString Whois data must contain this string if the domain is free
    */
    function addExtension($sExtension, $sServer, $sFreeString){
    if(!empty($sExtension) AND !empty($sServer) AND

    $sExtension)
    foreach($this->aExtensions as $sExt => $sServer)
    if(substr($sExtension, strlen($sExt)*-1) == $sExt)
    $sExtension = $sExt;

    if(empty($sDomain) OR empty($sExtension)){
    return self::NO_DATA;
    }

    $sDomainName = $sDomain .".". $sExtension;

    if(!preg_match("/^[w.-_]+$/i", $sDomainName)){
    return self::INVALID_NAME;
    }

    if(!isset($this->aExtensions[$sExtension])){
    return self::NO_EXTENSION;
    }
    $aExtensionData = $this->aExtensions[$sExtension];
    $sDomainName = escapeshellcmd($sDomainName);

    if($bUnix){
    if($sExtension "nl"){ $this->sExecCode = "whois -h ".$aExtensionData[0]." "is ".$sDomainName."""; } else { $this->sExecCode = "whois -h ".$aExtensionData[0]." "".$sDomainName."""; } exec($this->sExecCode, $sBuffer); if(!is_array($sBuffer) OR empty($sBuffer)){ return self::ERROR; } $this->sResult = ""; foreach($sBuffer as $sRow){ $this->sResult .= $sRow."n"; } if(stristr($this->sResult, "Connection refused") OR stristr($this->sResult, "No address associated with hostname")){ return self::NO_SERVER; } } else { if($sExtension "nl"){
    $this->sExecCode = "is ".$sDomainName;
    } else {
    $this->sExecCode = $sDomainName;
    }
    $rSocket = fsockopen($aExtensionData0, $this->iPort);
    if(!$rSocket){
    return self::NO_SERVER;
    }
    fputs($rSocket, $this->sExecCode);
    $this->sResult = "";
    while(!feof($rSocket))
    $this->sResult .= fgets($rSocket, 128);
    }

    if($bRaw){
    return $this->sResult;
    }

    if(stristr($this->sResult, $aExtensionData1)){
    return self::AVAILABLE;
    } else {
    return self::TAKEN;
    }

    }

    /**
    * Returns the last server response
    */
    public function getLastResponse(){
    if(isset($this->sResult))
    return $this->sResult;
    }
    }
    ?>

    Tags » PHP Webdevelopment
    • 14 June 2005
    • Views
    • Permalink
    • 0 responses
    • Like
    • Comment
  • Edwin Vlieg's Space

    Co-founder at MoneyBird, Entrepreneur, Software Engineer.

  • About Edwin Vlieg

    Co-founder at MoneyBird, Entrepreneur, Software Engineer.

  • Subscribe via RSS

    Archive

    2006 (23)
    September (1)
    August (6)
    July (1)
    June (1)
    May (1)
    April (6)
    March (5)
    February (2)
    2005 (2)
    December (1)
    June (1)
    2004 (1)
    September (1)
  • Follow Me

Theme created for Posterous by Obox