编写域查找工具

发布于 2024-10-18 03:44:34 字数 2314 浏览 1 评论 0原文

我一直在编写一个域检查器,并且真的很喜欢 php.ini。这就是我到目前为止所遇到的:

<?php
set_time_limit(0);
ob_start();
$domain = $_GET['domain'];
########### Extensions to be checked
$extensions = array(
    '.com'      => array('whois.crsnic.net','No match for'),
    '.info'     => array('whois.afilias.net','NOT FOUND'),  
    '.net'      => array('whois.crsnic.net','No match for'),
    '.co.uk'    => array('whois.nic.uk','No match'),        
    '.nl'       => array('whois.domain-registry.nl','not a registered domain'),
    '.ca'       => array('whois.cira.ca', 'AVAIL'),
    '.name'     => array('whois.nic.name','No match'),
    '.ws'       => array('whois.website.ws','No Match'),
    '.be'       => array('whois.ripe.net','No entries'),
    '.org'      => array('whois.pir.org','NOT FOUND'),
    '.biz'      => array('whois.biz','Not found'),
    '.tv'       => array('whois.nic.tv', 'No match for'),
);
###########

if(isset($domain))
{
    $newdomain = str_replace(array('www.', 'http://'), NULL, $domain);
    $finaldomain = str_replace($extensions, NULL, $newdomain);

    if(strlen($finaldomain) > 0)
    {
        foreach($extensions as $extension => $who)
        {
            $buffer = NULL;

            $sock = fsockopen($who[0], 43) or die('Error Connecting To Server:' . $server);
            fputs($sock, $finaldomain.$extension . "\r\n");

                while( !feof($sock) )
                {
                    $buffer .= fgets($sock,128);
                }

            fclose($sock);

            if(eregi($who[1], $buffer))
            {
                echo '<h4 class="available"><span>Available</span>' . $finaldomain. '<b>' . $extension .'</b> is Available</h4>';
            }
            else
            {
                echo '<h4 class="taken"><span>Taken</span>' . $finaldomain . '<b>' .$extension .'</b> is Taken</h4>';
            }
            echo '<br />';  

            ob_flush();
            flush();
            sleep(0.3);

        }
    }
    else
    {
        echo 'Please enter the domain name';
    }
}
?>

我遇到的问题是我不知道如何从传递的域中删除扩展名。

然后,当它返回结果时,我希望他们输入的扩展名成为结果列表中的第一个。

我是 php 新手,但我的项目需要这个。感谢所有帮助。

谢谢 乔

I have been coding a domain checker and really stuck with the php. This is what i have so far:

<?php
set_time_limit(0);
ob_start();
$domain = $_GET['domain'];
########### Extensions to be checked
$extensions = array(
    '.com'      => array('whois.crsnic.net','No match for'),
    '.info'     => array('whois.afilias.net','NOT FOUND'),  
    '.net'      => array('whois.crsnic.net','No match for'),
    '.co.uk'    => array('whois.nic.uk','No match'),        
    '.nl'       => array('whois.domain-registry.nl','not a registered domain'),
    '.ca'       => array('whois.cira.ca', 'AVAIL'),
    '.name'     => array('whois.nic.name','No match'),
    '.ws'       => array('whois.website.ws','No Match'),
    '.be'       => array('whois.ripe.net','No entries'),
    '.org'      => array('whois.pir.org','NOT FOUND'),
    '.biz'      => array('whois.biz','Not found'),
    '.tv'       => array('whois.nic.tv', 'No match for'),
);
###########

if(isset($domain))
{
    $newdomain = str_replace(array('www.', 'http://'), NULL, $domain);
    $finaldomain = str_replace($extensions, NULL, $newdomain);

    if(strlen($finaldomain) > 0)
    {
        foreach($extensions as $extension => $who)
        {
            $buffer = NULL;

            $sock = fsockopen($who[0], 43) or die('Error Connecting To Server:' . $server);
            fputs($sock, $finaldomain.$extension . "\r\n");

                while( !feof($sock) )
                {
                    $buffer .= fgets($sock,128);
                }

            fclose($sock);

            if(eregi($who[1], $buffer))
            {
                echo '<h4 class="available"><span>Available</span>' . $finaldomain. '<b>' . $extension .'</b> is Available</h4>';
            }
            else
            {
                echo '<h4 class="taken"><span>Taken</span>' . $finaldomain . '<b>' .$extension .'</b> is Taken</h4>';
            }
            echo '<br />';  

            ob_flush();
            flush();
            sleep(0.3);

        }
    }
    else
    {
        echo 'Please enter the domain name';
    }
}
?>

The problem I am having is that i don't know how i could remove the extension from the passed domain.

Then when it returns the results i want the extension they typed to be the first in the results list.

I am new to php but need this for my project. All help appreciated.

Thanks
Joe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光下的泡沫是彩色的 2024-10-25 03:44:34

首先,扩展名被称为顶级域(缩写为TLD)。其次,.co.uk 不是顶级域名,.uk 才是。它还具有其他子域,例如 .org.uk.gov.uk 等。

现在,要返回文件名/域名的扩展名部分,您可以使用 pathinfo

$tld = pathinfo('helloworld.co.uk', PATHINFO_EXTENSION);
echo $tld;   // uk

您可能需要修改数组以删除放置在那里的标题点,或者简单地:

$tld = '.' . pathinfo('helloworld.co.uk', PATHINFO_EXTENSION);
$whois_server = $extensions[$tld];

First of all, the extension is called a top-level domain (abbreviated TLD). Secondly, .co.uk is not a top-level domain, .uk is. It also has other subdomains like .org.uk, .gov.uk and so on.

Now, to return the extension part of a filename/domain name, you can use pathinfo:

$tld = pathinfo('helloworld.co.uk', PATHINFO_EXTENSION);
echo $tld;   // uk

You may have to modify your array to remove the headings dots you have put there, or simply:

$tld = '.' . pathinfo('helloworld.co.uk', PATHINFO_EXTENSION);
$whois_server = $extensions[$tld];
明月松间行 2024-10-25 03:44:34

您只需查询 TLD.whois-servers.net 即可,而无需为每个 TLD 提供所有 Whois 服务器。

来自维基百科

whois-servers.net 提供 DNS 别名
TLD WHOIS 服务器的记录 (CNAME)
格式为 .whois-servers.net。
GNU WHOIS 实用程序自动
使用 whois-servers.net 服务。

Instead of having all those Whois servers for each TLD you can just query TLD.whois-servers.net.

From Wikipedia:

whois-servers.net provides DNS alias
records (CNAME) for TLD WHOIS servers
of the form .whois-servers.net.
The GNU WHOIS utility automatically
uses the whois-servers.net service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文