无数据库的详细域名查询程序PHP版(1)


Posted in PHP onOctober 09, 2006

文件一:index.php

<?php

echo "<!-- Powered by MWhois written by Matt Wilson <matt@mattsscripts.co.uk> -->\\n\";

/*
    #########################################################################################
    #                                                                                       #
    #  本域名查询系统由mydowns收集整理汉化,汉化归把握时间网站所有(http://www.85time.com)   #
    #  该程序是2001年5月18日发布的最新版本,本站将对此程序继续进行修改完善,敬请关注本站!  #
    #  该程序可以查询域名所有者的详细资料信息,现提供9个类型的域名以供查询!                #
    #  演示地址:http://www.85time.com/whois                                                #
    #  源程序打包下载:http://www.85time.com/mydowns/mydowns.php?id=378                     #
    #  把握时间网站提供PHP、ASP、CGI、HTML、JSP等源程序、电子教材、文章资料                 #
    #  把握时间网站http://www.85time.com  把握时间论坛http://ww.85time.ent                  #
    #  请保留此信息,谢谢!                                                                 #
    #                                                                                       #
    #########################################################################################
    MWhois - a Whois lookup script written in PHP and Perl
    Copyright (C) 2000 Matt Wilson

    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
*/

if(!isset($use_global_templates))
    $use_global_templates = 1;    // whether to use the global templates

$template_header = \"gheader.tml\";    // the global header template
$template_footer = \"gfooter.tml\";    // the global footer template

/* Template information stuff
  ----------------------------
  The following strings in your templates are replaced with the description;

    [>DOMAIN<] = domain searching for
    [>RAWOUTPUT<] = the raw output of the whois query
    [>WHOIS_SERVER<] = the whois server used
    [>AVAIL_LIST<] = a list of the available domains (in global/wizard search mode)
    [>UNAVAIL_LIST<] = a list of the unavailable domains (in global/wizard search mode)
    [>ERROR_MSG<] = the error message produced
    [>EXT<] = the extension if it is set
    [>EXT_HTML_LIST<] = a list of the extensions supported in a html list
    [>EXT_LIST<] = a list of extensions supported

  parameters to the script (no parameters brings up normal search script);

    show_raw=1    = wherther to show the raw output page
    do_wizard=1    = whether the information being passed is for the wizard
    domain=(string) = do a search for the domain (string)
    list_exts=1    = show the extensions supported page
    do_global=1    = goto the global search page
    do_mini_search=1 = just show the search form without anything else
    company=(string) = used for the wizard, needed in order to search
    keyword1=(string) = used for the wizard, needed in order to search
    keyword2=(string) = used for the wizard, needed in order to search

  If any of this is unclear, see the provided example templates
*/

$template_search_mini = \"searchform.tml\";    // search template
$template_search = \"searchmain.tml\";
$template_raw_output = \"rawoutput.tml\";    // raw output template
$template_available = \"isavail.tml\";    // template for available
$template_taken = \"istaken.tml\";    // template for taken
$template_wizard = \"wizard.tml\";    // template for the domain wizard
$template_wizard_results = \"wizardres.tml\"; // the output template for the domain wizard
$template_error = \"error.tml\";    // the template in case of error
$template_exts_list = \"exts_list.tml\";
$template_global = \"global.tml\";
$template_global_results = \"globres.tml\";

$search_title = \"Let Floyd find your domain name\";
$raw_output_title = \"Floyd\'s Raw WHOIS Output\";
$available_title = \"Floyd says Domain Name Available!\";
$taken_title = \"Floyd says Doman Name in use\";
$wizard_title = \"Floyd the Domain Name Wizard\";
$error_title = \"Floyd Encountered an Error!\";
$exts_list_title = \"Floyd supports the following extensions\";
$global_title = \"Let Floyd do the hard work!\";

// the extensions that we are going to be using, edit these for your needs
$whois_exts = array(
    \"com\",
    \"net\",
    \"org\",
    \"com.cn\",
    \"net.cn\",
    \"org.cn\",
    \"gov.cn\",
    \"sh\",
    \"cc\"
);

// some extensions (com/net/org) have a server which contains the name of the server which should be used for  

the information, this simply tells the script to use the whois server as a source for the server info... ;)
$whois_si_servers = array();

// an array of the `whois\' servers
$whois_servers = array();

// default whois servers for info
$whois_info_servers = array();

// the backup whois servers to try
$whois_info_servers_backup = array();

// the strings that are returned if the domain is available
$whois_avail_strings = array();

// some substitution strings follow
$errormsg = \"\";
$titlebar = \"MWhois written by Matt Wilson\";    // the defatul title bar
$rawoutput = \"\";
$avail = array();
$unavail = array();
$whois_server = \"\";

// the name of the script
$script_name = \"index.php\";

function my_in_array($val,$array_)
{
    for($l=0; $l<sizeof($array_); $l++)
        if($array_[$l] == $val)
            return 1;

    return 0;
}

// this loads the server info for the extensions in $whois_exts;
function load_server_info()
{
    global $whois_exts;
    global $whois_si_servers;
    global $whois_servers;
    global $whois_info_servers;
    global $whois_info_servers_backup;
    global $whois_avail_strings;

    // load the servers.lst file
    $tlds = file(\"servers.lst\");

    for($l=0; $l<sizeof($tlds); $l++){
        // time leading spaces or trailing spaces
        $tlds[$l] = chop($tlds[$l]);

        // filter out the commented lines (begin with #)
        if(substr($tlds[$l], 0, 1) == \"#\" || !strlen($tlds[$l])) { continue; }

        // explode via the seperation char `|\'
        $es = explode(\"|\", $tlds[$l]);

        // check to see whether we want this TLD
        if(!my_in_array($es[0], $whois_exts)) { continue; }

        // yes we do, so store the details in the appropriate arrays
        $whois_servers[$es[0]] = $es[1];
        $whois_si_servers[$es[0]] = $es[5];
        $whois_info_servers[$es[0]] = $es[3];
        $whois_info_servers_backup[$es[0]] = $es[4];
        $whois_avail_strings[$es[1]] = $es[2];

        // thats it!
    }
}

function choose_info_server($domain, $ext)
{
    global $whois_info_servers;
    global $whois_si_servers;
    global $whois_server;
    global $whois_servers;

    $whois_server = \"\";

    if($whois_si_servers[$ext]){
        if(($co = fsockopen($whois_servers[$ext], 43)) == false){
            echo \"<!-- choose_info_server() : unable to connect to \".$whois_servers[$ext].\" @ line  

#\".$__LINE__.\" -->\\n\";
            $whois_server = $whois_servers[$ext];
        } else {
            echo \"<!-- choose_info_servers() : connected to \".$whois_servers[$ext].\" @ line  

#\".$__LINE__.\", looking for `\".$whois_si_servers[$ext].\"\' -->\\n\";
            fputs($co, $domain.\".\".$ext.\"\\n\");
            while(!feof($co))
                $output .= fgets($co,128);

            fclose($co);

            $he = strpos($output, $whois_si_servers[$ext]) + strlen($whois_si_servers[$ext]);
            $le = strpos($output, \"\\n\", $he);
            $whois_server = substr($output, $he, $le-$he);
            echo \"<!-- choose_info_servers() : found `\".$whois_server.\"\' @ line #\".$__LINE__.\",  

using for whois info server -->\\n\";
        }
    } else {
        $whois_server = $whois_info_servers[$ext];
    }

    $whois_server = trim($whois_server);
}

// make all the changes
function make_changes($fil)
{
    global $domain;
    global $errormsg;
    global $titlebar;
    global $rawoutput;
    global $avail;
    global $unavail;
    global $ext;
    global $whois_exts;
    global $whois_servers;
    global $script_name;

    $f = implode(\"\",file($fil));

    $f = str_replace(\"[>WHOIS_SERVER<]\",$whois_servers[$ext],$f);
    $f = str_replace(\"[>TITLE_BAR<]\",$titlebar,$f);
    $f = str_replace(\"[>DOMAIN<]\",$domain,$f);
    $f = str_replace(\"[>ERROR_MSG<]\",$errormsg,$f);
    $f = str_replace(\"[>RAWOUTPUT<]\",$rawoutput,$f);

    for($l=0; $l<sizeof($avail); $l++){
        $sp[1] = substr(strchr($avail[$l],\".\"),1);
        $sp[0] = substr($avail[$l],0,strlen($avail[$l])-strlen($sp[1])-1);
        $avail_s = $avail_s.\"<a  

href=\\\"\".$script_name.\"?domain=\".$sp[0].\"&ext=\".$sp[1].\"\\\">\".$avail[$l].\"</a><br>\";
    }

     for($l=0; $l<sizeof($unavail); $l++){
                $sp[1] = substr(strchr($unavail[$l],\".\"),1);
                $sp[0] = substr($unavail[$l],0,strlen($unavail[$l])-strlen($sp[1])-1);
                $unavail_s = $unavail_s.\"<a  

href=\\\"\".$script_name.\"?domain=\".$sp[0].\"&ext=\".$sp[1].\"\\\">\".$unavail[$l].\"</a><br>\";
    }

    $f = str_replace(\"[>AVAIL_LIST<]\",$avail_s,$f);
    $f = str_replace(\"[>UNAVAIL_LIST<]\",$unavail_s,$f);
    $f = str_replace(\"[>SCRIPT_NAME<]\", $script_name, $f);
    $f = str_replace(\"[>EXT<]\",$ext,$f);
    $f = str_replace(\"[>EXT_LIST<]\",implode(\"<br>\",$whois_exts),$f);
    $f = str_replace(\"[>EXT_HTML_LIST<]\",\"<select  

name=ext>\\n<option>\".implode(\"\\n<option>\",$whois_exts).\"\\n</select>\",$f);

    return $f;
}

// show the error page
function do_error()
{
    global $use_global_templates;
    global $template_header;
    global $template_footer;
    global $template_error;
    global $domain;
    global $titlebar;
    global $error_title;
    global $errormsg;

    $titlebar = $error_title;

    if($use_global_templates)
        echo make_changes($template_header);

    echo make_changes($template_error);

    if($use_global_templates)
        echo make_changes($template_footer);

    exit();
}

// checks the domain is legal
function check_domain()
{
    global $errormsg;
    global $domain;
    global $ext;
    global $whois_exts;

    if(isset($ext)){
        if(!strlen($ext)){
            $errormsg = \"没有选择域名后缀\";
            return 0;
        }
        if(!my_in_array($ext,$whois_exts)){
            $errormsg = \"不支持此域名后缀\";
            return 0;
        }
    }
    if(isset($domain)){
        if(strlen($domain) < 2 || strlen($domain) > 57){
            $errormsg = \"域名太长或太短\";
            return 0;
        }
        if(strlen($domain) == 2 && !ereg(\"([0-9]){2}\",$domain)){
            $errormsg = \"在2个字节的域名中不能包含有字母\";
            return 0;
        }
        if(ereg(\"^-|-$\",$domain)){
            $errormsg = \"域名前和域名后不能使用-,也不可以连续使用-\";
            return 0;
        }
        if(!ereg(\"([a-z]|[A-Z]|[0-9]|-){\".strlen($domain).\"}\",$domain)){
            $errormsg = \"域名只可以包含字母数字组合和-\";
            return 0;
        }
    }

    return 1;
}

// perform_whois function returns 0 if domain is available otherwise returns either the raw info or 1
function perform_whois($domainname,$ext,$raw)
{
    global $errormsg;
    global $whois_servers;
    global $rawoutput;
    global $whois_avail_strings;

    $rawoutput = \"\";

    if($raw)
        return do_raw($domainname,$ext);

    if(($ns = fsockopen($whois_servers[$ext],43)) == false){
        $errormsg = \"无法连接到域名查询服务器 <b><i>\".$whois_servers[$ext].\"</i></b>\";
        return -1;
    }
    fputs($ns,\"$domainname.$ext\\n\");
    while(!feof($ns))
        $rawoutput .= fgets($ns,128);

    fclose($ns);

    echo \"<!--\\nAvail string = \\\"\".$whois_avail_strings[$whois_servers[$ext]].\"\\\"\\nComparing against =  

\\\"\".$rawoutput.\"\\\"\\n-->\\n\";

    if(!ereg($whois_avail_strings[$whois_servers[$ext]], $rawoutput))
        return 0;

    return 1;
}

// this performs the whois lookup and then shows the data returned
function do_raw($domainname, $ext)
{
    global $titlebar;
    global $template_raw_output;
    global $use_global_templates;
    global $template_header;
    global $template_footer;
    global $raw_output_title;
    global $whois_info_servers;
    global $whois_servers;
    global $rawoutput;
    global $errormsg;
    global $whois_info_servers_backup;
    global $whois_avail_strings;
    global $whois_server;

    choose_info_server($domainname, $ext);

    if(($ns = fsockopen($whois_server,43)) == false){
        if(($ns = fsockopen($whois_info_servers[$ext],43)) == false){
            if(($ns = fsockopen($whois_info_servers_backup[$ext], 43)) == false){
                        return -1;
            } else {
                $whois_server = $whois_info_servers_backup[$ext];
            }
        } else {
            $whois_server = $whois_info_servers[$ext];
        }
    }

    print \"<!-- do_raw() : using `\".$whois_server.\"\' for whois query -->\\n\";

        fputs($ns,\"$domainname.$ext\\n\");
        while(!feof($ns))
                $rawoutput = $rawoutput.fgets($ns,128);

        fclose($ns);

    echo \"<!--\".$rawoutput.\"-->\";

//    $pos = @strpos($rawoutput,$whois_avail_strings[$server]);
//    if(is_string($pos) && !$pos){}
//    else{
//    if(!is_string($pos) || $pos){
//        if(($ns = fsockopen($whois_info_servers_backup[$ext],43)) == false)
//            return -1;
//        else{
//            $rawoutput = \"\";
//            fputs($ns,\"$domainname.$ext\\n\");
//            while(!feof($ns))
//                $rawoutput = $rawoutput.fgets($ns,128);
//            $pos = @strpos($rawoutput,$whois_avail_strings[$whois_info_servers_backup[$ext]]);
//            if(!is_string($pos) || $pos){}
//            else
//                return -1;
//        }
//    }

    $titlebar = $raw_output_title;

        if($use_global_templates)
                echo make_changes($template_header);

        echo make_changes($template_raw_output);

        if($use_global_templates)
                echo make_changes($template_footer);

    exit();
}

function do_getsearch_mini()
{
        global $template_search_mini;

        echo make_changes($template_search_mini);

    exit();
}

function do_getsearch()
{
        global $template_footer;
        global $template_header;
        global $use_global_templates;
        global $titlebar;
        global $template_search;
    global $search_title;

        $titlebar = $search_title;

        if($use_global_templates)
                echo make_changes($template_header);

        echo make_changes($template_search);

        if($use_global_templates)
                echo make_changes($template_footer);

        exit();     
}

function do_avail()
{
    global $template_footer;
    global $template_header;
    global $use_global_templates;
    global $titlebar;
    global $template_available;
    global $available_title;

        $titlebar = $available_title;

        if($use_global_templates)
                echo make_changes($template_header);

        echo make_changes($template_available);

        if($use_global_templates)
                echo make_changes($template_footer);

    exit();
}

function do_taken()
{
    global $template_footer;
    global $template_header;
    global $use_global_templates;
    global $template_taken;
    global $titlebar;
    global $taken_title;

        $titlebar = $taken_title;

        if($use_global_templates)
                echo make_changes($template_header);

        echo make_changes($template_taken);

        if($use_global_templates)
                echo make_changes($template_footer);

    exit();
}

function do_exts()
{
        global $template_footer;
        global $template_header;
        global $use_global_templates;
        global $template_exts_list;
        global $titlebar;
        global $exts_list_title;

        $titlebar = $exts_list_title;

        if($use_global_templates)
                echo make_changes($template_header);

        echo make_changes($template_exts_list);

        if($use_global_templates)
                echo make_changes($template_footer);

        exit();
}

function do_glob()
{
    global $domain;
    global $whois_exts;
    global $avail;
    global $unavail;
    global $template_header;
        global $template_footer;
        global $use_global_templates;
        global $titlebar;
        global $global_title;

    $titlebar = $global_title;

    if($use_global_templates)
        echo make_changes($template_header);

    if(!isset($domain)){
            global $template_global;

            echo make_changes($template_global);
    }
    else{
        global $template_global_results;

        for($l=0; $l<sizeof($whois_exts); $l++){
            if(($r = perform_whois($domain,$whois_exts[$l],0)) != -1){
                if(!$r)
                    $avail[] = $domain.\".\".$whois_exts[$l];
                else
                    $unavail[] = $domain.\".\".$whois_exts[$l];
            }
        }

        echo make_changes($template_global_results);
    }

    if($use_global_templates)
        echo make_changes($template_footer);

    exit();
}

function do_wiz()
{
        global $domain;
    global $ext;
        global $avail;
        global $unavail;
        global $template_header;
        global $template_footer;
        global $use_global_templates;
        global $titlebar;
        global $wizard_title;
    global $errormsg;
    global $keyword1;
    global $keyword2;
    global $company;

        $titlebar = $wizard_title;

        if($use_global_templates)
                echo make_changes($template_header);

    if(!isset($company) || !isset($keyword1) || !isset($keyword2)){
                global $template_wizard;

                echo make_changes($template_wizard);
        }
        else{
                global $template_wizard_results;

        $domains = array(
            $company,
            $company.$keyword1,
            $company.\"-\".$keyword1,
            $keyword1.$company,
            $keyword1.\"-\".$company,
                        $company.$keyword2,
                        $company.\"-\".$keyword2,
                        $keyword2.$company,
                        $keyword2.\"-\".$company,
            $keyword1,
            $keyword2,
            $keyword1.$keyword2,
            $keyword2.$keyword1,
            $keyword1.\"-\".$keyword2,
            $keyword2.\"-\".$keyword1
        );

        for($l=0; $l<sizeof($domains); $l++){
            $domain = strtolower(str_replace(\" \",\"\",$domains[$l]));
            if(check_domain()){
                if(($r = perform_whois($domain,$ext,0)) != -1){
                    if(!$r)
                        $avail[] = $domain.\".\".$ext;
                    else
                        $unavail[] = $domain.\".\".$ext;
                }
            }
        }

                echo make_changes($template_wizard_results);
        }

        if($use_global_templates)
                echo make_changes($template_footer);

    exit();
}

load_server_info();

if(!check_domain())
    do_error();

if(isset($do_wizard))
    do_wiz();

if(isset($do_global))
    do_glob();

if(isset($list_exts))
    do_exts();

if(isset($do_mini_search))
    do_getsearch_mini();

if(!isset($domain))
    do_getsearch();

if(isset($show_raw)){
    if(perform_whois($domain,$ext,1) != -1)
        $errormsg = \"MWhois域名查询内部错误\";

    do_error();
}

$ret = perform_whois($domain,$ext,0);
if($ret == -1)
    do_error();

if(!$ret)
    do_taken();
else
    do_avail();

?>

PHP 相关文章推荐
不用数据库的多用户文件自由上传投票系统(1)
Oct 09 PHP
PHP如何得到当前页和上一页的地址?
Nov 27 PHP
php数组函数序列之array_search()- 按元素值返回键名
Nov 04 PHP
用Zend Studio+PHPnow+Zend Debugger搭建PHP服务器调试环境步骤
Jan 19 PHP
PHP采用超长(超大)数字运算防止数字以科学计数法显示的方法
Apr 01 PHP
php is_executable判断给定文件名是否可执行实例
Sep 26 PHP
PHP中使用jQuery+Ajax实现分页查询多功能操作(示例讲解)
Sep 17 PHP
php 数据结构之链表队列
Oct 17 PHP
PHP与以太坊交互详解
Aug 24 PHP
php 使用 __call实现重载功能示例
Nov 18 PHP
PHP 超级全局变量相关总结
Jun 30 PHP
聊聊 PHP 8 新特性 Attributes
Aug 19 PHP
无数据库的详细域名查询程序PHP版(2)
Oct 09 #PHP
PHP调用三种数据库的方法(3)
Oct 09 #PHP
PHP调用三种数据库的方法(2)
Oct 09 #PHP
PHP调用三种数据库的方法(1)
Oct 09 #PHP
php数据库连接
Oct 09 #PHP
基于文本的访客签到簿
Oct 09 #PHP
基于文本的搜索
Oct 09 #PHP
You might like
PHP封装的一个支持HTML、JS、PHP重定向的多功能跳转函数
2014/06/19 PHP
php实现上传图片保存到数据库的方法
2015/02/11 PHP
PHP实践教程之过滤、验证、转义与密码详解
2017/07/24 PHP
javascript 对象的定义方法
2007/01/10 Javascript
js中的eventType事件及其浏览器支持性介绍
2013/11/29 Javascript
jquery制作 随机弹跳的小球特效
2015/02/01 Javascript
jQuery插件datatables使用教程
2016/04/21 Javascript
jQuery EasyUI学习教程之datagrid点击列表头排序
2016/07/09 Javascript
javascript 正则表达式去空行方法
2017/01/24 Javascript
javascript 中Cookie读、写与删除操作
2017/03/29 Javascript
PM2自动部署代码步骤流程总结
2018/12/10 Javascript
vue elementUI 表单校验的实现代码(多层嵌套)
2019/11/06 Javascript
JS出现404错误原理及解决方案
2020/07/01 Javascript
[01:19]DOTA2城市挑战赛报名开始 开启你的城市传奇
2018/03/23 DOTA
Python struct模块解析
2014/06/12 Python
跟老齐学Python之Python安装
2014/09/12 Python
python简单程序读取串口信息的方法
2015/03/13 Python
使用Python编写一个模仿CPU工作的程序
2015/04/16 Python
Python实现基于二叉树存储结构的堆排序算法示例
2017/12/08 Python
Python3使用正则表达式爬取内涵段子示例
2018/04/22 Python
10分钟教你用python动画演示深度优先算法搜寻逃出迷宫的路径
2019/08/12 Python
利用Python产生加密表和解密表的实现方法
2019/10/15 Python
python 协程中的迭代器,生成器原理及应用实例详解
2019/10/28 Python
检测浏览器对HTML5和CSS3支持度的方法
2015/06/25 HTML / CSS
美国宠物商店:Wag.com
2016/10/25 全球购物
留学自荐信
2013/10/10 职场文书
优秀毕业大学生推荐信
2013/11/13 职场文书
2014年党课学习材料
2014/05/11 职场文书
安全环保标语
2014/06/09 职场文书
党的群众路线教育实践活动专题组织生活会发言材料
2014/10/17 职场文书
公司股份合作协议书
2014/12/07 职场文书
教师听课评语大全
2014/12/31 职场文书
市直属机关2016年主题党日活动总结
2016/04/05 职场文书
微信告警的zabbix监控系统 监控整个NGINX集群
2022/04/18 Servers
图神经网络GNN算法
2022/05/11 Python
小程序实现侧滑删除功能
2022/06/25 Javascript