The IsProxy interface offers the most efficient way to check domain name validity and availability. It reduces overhead by using a telnet based protocol that allows multiple checks to be made in parallel. The interface can be used most effectively by reusing existing sessions as much as possible, this will lower the overhead on session creation and authentication.
The API is available on two different locations. A production environment and a test environment.
The IsProxy supports a number of commands.
>>> LOGIN apikey <<< 100 Login ok >>> IS example1.com <<< example1.com not available >>> IS example2.com >>> IS example3.net >>> IS example4.info <<< example2.com available <<< example4.info not available <<< example3.net not available >>> IS --.org <<< --.org invalid domain >>> QUIT
Class implementing the Isproxy protocol
<?php /** * Realtime Register is proxy * * <code> * require_once 'IsProxy.php'; * * $ip = new IsProxy("apikey"); * $ip->check('domainname', 'com'); * * $result = $ip->result(); * echo $result['domain'].' '.$result['result']; * * $ip->close(); * </code> */ class IsProxy { /** * Connection * * @var object */ private $fp; private $apikey; private $host; private $port; /** * Construct * * @param string The api key * @param string The IsProxy host, defaults to "is.yoursrs.com" * @param int The IsProxy port, defaults to 2001 * @return void */ public function __construct($apikey, $host = "is.yoursrs.com", $port = 2001) { $this->apikey = $apikey; $this->host = $host; $this->port = $port; } /** * Close * * @return void */ public function close() { $this->write('CLOSE'); @fclose($this->fp); } /** * Connect * * @return bool Connection established? */ private function connect() { $this->fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10); if(!is_resource($this->fp)) { return false; } /** * Login */ return $this->login(); } /** * Check * * @param string Domainname * @param mixed TLD(s) * @return void */ public function check($domainname, $tlds) { if(!is_array($tlds)) { $tlds = (array) $tlds; } foreach($tlds as $tld) { $this->write('IS '.$domainname.'.'.$tld); } } /** * Result * * @return array [ domain, result ] */ public function result() { $response = $this->read(); if(preg_match('#^([\-\w.]+)\s(available|not\savailable|invalid\sdomain|error)#', $response, $match)) { return array('domain' => $match[1], 'result' => $match[2]); } return array('domain' => '-', 'result' => 'error'); } /** * Is connected? * * @return bool Connection? */ public function is_connected() { return is_resource($this->fp); } /** * Login * * @return bool Login successfull? */ public function login() { if(!$this->write('LOGIN '.$this->apikey)) { return false; } $response = $this->read(); if(preg_match('#^400\sLogin\sfailed#', $response)) { return false; } return preg_match('#^100\sLogin\sok#', $response); } /** * Read * * @return string Response */ private function read() { if(!$this->is_connected()) { $this->connect(); } if(!$response = fgets($this->fp, 1024)) { return false; } return trim($response); } /** * Write * * @param string Message * @return bool Writing successfull? */ private function write($message) { if(!$this->is_connected()) { $this->connect(); } return @fputs($this->fp, $message."\r\n"); } }
Example usage of the IsProxy class.
<?php /** * Realtime Register is proxy example usage */ /** * Realtime Register is proxy api key */ $apikey = 'apikey'; /** * TLDs */ $tlds = array('com', 'net', 'org', 'info'); /** * Text */ $text = array( 'error' => 'Error', 'available' => 'Available', 'not available' => 'Not available', 'invalid domain' => 'Invalid domain', ); $domainname = isset($_REQUEST['domainname']) ? $_REQUEST['domainname'] : null; $tld = isset($_REQUEST['tld']) ? $_REQUEST['tld'] : null; echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo ' <table>'; echo ' <tr>'; echo ' <td><input type="text" name="domainname" value="'.$domainname.'" /></td>'; echo ' <td>.</td>'; echo ' <td><select name="tld"><option value="all" '.($tld == 'all' ? 'selected="selected"' : null).'>(all)</option>'; foreach($tlds as $opt) { echo ' <option value="'.$opt.'"'.($tld == $opt ? 'selected="selected"' : null).'>'.$opt.'</option>'; } echo ' </select></td>'; echo ' <td><input type="submit" value="Check" /></td>'; echo ' </tr>'; echo ' </table>'; echo '</form>'; if($_SERVER['REQUEST_METHOD'] == 'POST') { if(is_null($domainname) || is_null($tld)) { echo '<p>Ongeldige domeinnaam</p>'; } else { /** * Initiate Realtime Register whois proxy */ require_once 'IsProxy.php'; $ip = new IsProxy($apikey); $tld_check = $tld == 'all' ? $tlds : (array) $tld; $tld_count = sizeof($tld_check); $a = 0; echo '<table>'; $ip->check($domainname, $tld_check); while($result = $ip->result()) { $a++; echo '<tr><td>'.$result['domain'].'</td><td>'.$text[$result['result']].'</td></tr>'; flush(); if($a == $tld_count) { $ip->close(); break; } } echo '</table>'; } }