NEW TAG: WHOIS
Posted: Thu Jul 19, 2007 9:14 pm
Hi guys,
here below my useful tag called simply: WHOIS.
What is the whois?
WHOIS is a TCP-based query/response protocol which is widely used for querying a database in order to determine the owner of a domain name, an IP address, or an autonomous system number on the Internet. WHOIS lookups were traditionally made using a command line interface, but a number of simplified web-based tools now exist for looking up domain ownership details from different databases. Web-based WHOIS clients still rely on the WHOIS protocol to connect to a WHOIS server and do lookups, and command-line WHOIS clients are still quite widely used by system administrators.
What is the TAG: {whois} ?
The tag whois is a little form that helps all users to know if a particular domain is available. This simple request of information to a specific server will return a result that shows if a domain is already taken or not.
The extensions supported are: eu, it, com, net, org, name, biz, info, nl, be, de;
Here below the TAG file: function.whois.php
here below my useful tag called simply: WHOIS.
What is the whois?
WHOIS is a TCP-based query/response protocol which is widely used for querying a database in order to determine the owner of a domain name, an IP address, or an autonomous system number on the Internet. WHOIS lookups were traditionally made using a command line interface, but a number of simplified web-based tools now exist for looking up domain ownership details from different databases. Web-based WHOIS clients still rely on the WHOIS protocol to connect to a WHOIS server and do lookups, and command-line WHOIS clients are still quite widely used by system administrators.
What is the TAG: {whois} ?
The tag whois is a little form that helps all users to know if a particular domain is available. This simple request of information to a specific server will return a result that shows if a domain is already taken or not.
The extensions supported are: eu, it, com, net, org, name, biz, info, nl, be, de;
Here below the TAG file: function.whois.php
Code: Select all
<?php
#CMS - CMS Made Simple
#(c)2007 - 2008 by Michelangelo Turillo (mturillo@gmail.com)
# Copyright (c) 2004 - 2005, Olaf Lederer
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function smarty_cms_function_whois($params, &$smarty)
{
global $gCms;
$pageinfo = &$gCms->variables['pageinfo'];
$config = &$gCms->GetConfig();
if (isset($pageinfo) && $pageinfo->content_id == -1)
{
#We've a custom error message... set a current timestamp
return "404 Error";
}
else
{
$result = CreateForm();
return $result;
}
}
function smarty_cms_help_function_whois() {
?>
<h3>What does this do?</h3>
<p>Prints the whois of a domain.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like: <code>{whois}</code></p>
<h3>What parameters does it take?</h3>
<p>None at this time.</p>
<?php
}
function smarty_cms_about_function_whois() {
?>
<p>Author: Michelangelo Turillo <mturillo@gmail.com></p>
<p>Version: 1.0</p>
<p>
Change History:<br/>
None
</p>
<?php
}
function CreateForm()
{
// ADD HERE A SERVER
$servers['eu']['address'] = "whois.eu";
$servers['eu']['free'] = "not found in database";
$servers['eu']['param'] = "";
$servers['it']['address'] = "whois.nic.it";
$servers['it']['free'] = "not found in database";
$servers['it']['param'] = "";
$servers['com']['address'] = "whois.crsnic.net";
$servers['com']['free'] = "No match for";
$servers['com']['param'] = "";
$servers['net']['address'] = "whois.crsnic.net";
$servers['net']['free'] = "No match for";
$servers['net']['param'] = "";
$servers['org']['address'] = "whois.pir.org";
$servers['org']['free'] = "NOT FOUND";
$servers['org']['param'] = "";
$servers['name']['address'] = "whois.nic.name";
$servers['name']['free'] = "No match";
$servers['name']['param'] = "";
$servers['biz']['address'] = "whois.nic.biz";
$servers['biz']['free'] = "Not found";
$servers['biz']['param'] = "";
$servers['info']['address'] = "whois.afilias.net";
$servers['info']['free'] = "NOT FOUND";
$servers['info']['param'] = "";
$servers['nl']['address'] = "whois.domain-registry.nl";
$servers['nl']['free'] = "is free";
$servers['nl']['param'] = "is "; // is used only for free check
$servers['be']['address'] = "whois.dns.be";
$servers['be']['free'] = "free";
$servers['be']['param'] = "";
$servers['de']['address'] = "whois.denic.de";
$servers['de']['free'] = "not found in database";
$servers['de']['param'] = "-T dn "; // required!!
// error_reporting(E_ALL);
$my_whois = new Whois_domain;
$my_whois->possible_tlds = array_keys($servers); // this is the array from the included server list
if (isset($_POST['submit'])) {
$my_whois->tld = $_POST['tld'];
$my_whois->domain = $_POST['domain'];
$my_whois->free_string = $servers[$_POST['tld']]['free'];
$my_whois->whois_server = $servers[$_POST['tld']]['address'];
$my_whois->whois_param = $servers[$_POST['tld']]['param'];
$my_whois->full_info = (isset($_POST['all_info'])) ? $_POST['all_info'] : "no"; // between "no" and "yes" to get all whois information
$my_whois->process();
}
$result = '<h2>Check availability of Domain name</h2><p>Check if the domain is already taken.<br>If the result for a query is negative that a standard message is given. <br><br>Enter here the name for a domain name what you want to check<br>and select the type of tld you want to check.</p>
<form action="http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ."?". $_SERVER['QUERY_STRING'] . '" method="post" name="form">
http://www.<input type="text" name="domain" size="14" maxlength="63" value="';
$result .= (isset($_POST['domain'])) ? $_POST['domain'] : "";
$result .='">.';
$result .= $my_whois->create_tld_select(); // this method generates the select menu woth all tld\'s
$result .='<br><br>
Show all info? <input name="all_info" type="checkbox" value="yes">
<input name="submit" type="submit" value="Whois">
</form>
';
$result .= '<p>' . ($my_whois->msg != "") ? $my_whois->msg : "";
$result .= '</p>';
if ($my_whois->info != "") {
$result .= '<h2>Whois '.$my_whois->compl_domain.'?</h2><textarea id="whoisarea" rows="10" cols="50">';
$result .= nl2br($my_whois->info);
$result .= '</textarea>';
}
return $result;
}
class Whois_domain {
var $possible_tlds;
var $whois_server;
var $free_string;
var $whois_param;
var $domain;
var $tld;
var $compl_domain;
var $full_info;
var $msg;
var $info;
var $os_system = "linux"; // switch between "linux" and "win"
function Whois_domain() {
$this->info = "";
$this->msg = "";
}
function process() {
if ($this->create_domain()) {
if ($this->full_info == "yes") {
$this->get_domain_info();
} else {
if ($this->check_only() == 1) {
$this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
return true;
} elseif ($this->check_only() == 0) {
$this->msg = "The domain name: <b>".$this->compl_domain."</b> is registered";
return false;
} else {
$this->msg = "There was something wrong, try it agian.";
}
}
} else {
$this->msg = "Only letters, numbers and hyphens (-) are valid!";
}
}
function check_entry() {
if (preg_match("/^([A-Za-z0-9]+(\-?[A-za-z0-9]*)){2,63}$/", $this->domain)) {
return true;
} else {
return false;
}
}
function create_tld_select() {
$menu = "<select name=\"tld\" style=\"margin-left:0;\">\n";
foreach ($this->possible_tlds as $val) {
$menu .= " <option value=\"".$val."\"";
$menu .= (isset($_POST['tld']) && $_POST['tld'] == $val) ? " selected>" : ">";
$menu .= $val."\n";
}
$menu .= "</select>\n";
return $menu;
}
function create_domain() {
if ($this->check_entry()) {
$this->domain = strtolower($this->domain);
$this->compl_domain = $this->domain.".".$this->tld;
return true;
} else {
return false;
}
}
function check_only() {
$data = $this->get_whois_data();
if (is_array($data)) {
$found = 0;
foreach ($data as $val) {
if (eregi($this->free_string, $val)) {
$found = 1;
}
}
return $found;
} else {
$this->msg = "Error, please try it again.";
}
}
function get_domain_info() {
if ($this->create_domain()) {
$data = ($this->tld == "nl") ? $this->get_whois_data(true) : $this->get_whois_data();
if (is_array($data)) {
foreach ($data as $val) {
if (eregi($this->free_string, $val)) {
$this->msg = "The domain name: <b>".$this->compl_domain."</b> is free.";
$this->info = "";
break;
}
$this->info .= $val;
}
} else {
$this->msg = "Error, please try it again.";
}
} else {
$this->msg = "Only letters, numbers and hyphens (-) are valid!";
}
}
function get_whois_data($empty_param = false) {
// the parameter is new since version 1.20 and is used for .nl (dutch) domains only
if ($empty_param) {
$this->whois_param = "";
}
if ($this->tld == "de") $this->os_system = "win"; // this tld must be queried with fsock otherwise it will not work
if ($this->os_system == "win") {
$connection = @fsockopen($this->whois_server, 43);
if (!$connection) {
unset($connection);
$this->msg = "Can't connect to the server!";
return;
} else {
sleep(2);
fputs($connection, $this->whois_param.$this->compl_domain."\r\n");
while (!feof($connection)) {
$buffer[] = fgets($connection, 4096);
}
fclose($connection);
}
} else {
$string = "whois -h ".$this->whois_server." \"".$this->whois_param.$this->compl_domain."\"";
exec($string, $buffer);
}
if (isset($buffer)) {
//print_r($buffer);
return $buffer;
} else {
$this->msg = "Can't retrieve data from the server!";
}
}
}
?>