0

我想创建一个执行 WHOIS 查询以查看域是否可用的东西。现在,我找到了很多现成的脚本,但它们似乎都是一样的,你需要指定基础,然后选择你想要的扩展,它会这样做(例如,输入'test',检查.com,它会检查test.com是否可用)

但是,我正在尝试做一些其他的事情。我希望它做的事情是检查用户是否只输入了基本 URL 或完整 URL,然后相应地执行一个或多个查询。例子:

如果用户输入“test”,我希望脚本检查 test.com、test.org、test.net 等。如果用户输入“test.com”,我希望脚本检查 test.com .

我真的不知道要建立在什么基础上,但Mike Nott 的 PHP Whois 脚本看起来还不错。当然,建议总是受欢迎的。

现在我猜脚本流程应该是这样的:

  1. 用户输入查询
  2. 脚本检查空格
  3. 脚本检查用户输入的只是一个基本域名还是一个完整的域名(我猜想解决这个问题的方法是检查那里是否有一个点)
  4. 如果用户输入了完整的域名,则将基础域名和顶级域名分开并将它们存储在变量中并将“状态”存储在某处($full = true/false)
  5. if ($full = true) {检查 $base.com $base.net 等对应的 whois 服务器};
  6. if ($full != true) {查看 $tld 的正确服务器是什么并检查 $base.$tld 的服务器}
  7. 输出结果

当然,如果已经有脚本可以做到这一点,请告诉我。

编辑:您知道,我可以做简单的 if 语句等,但我的“工作流程”中的步骤 3、4、5 和 6 是我无法弄清楚的部分。

编辑2:感谢您的所有回答,伙计们!马库斯亚当的理论确实有效。我的域名经销商(我从中获取域名的人)不提供像 .co.uk 这样的二级 TLD,所以这不是问题。他们也不支持 IDN。

根据各位的回答,我得出的结论是explode函数是用来分隔域名的。但是,遇到多个点会爆炸怎么办?我猜它只会在数组中添加另一个条目,但这会导致问题。因为如果用户随后输入(例如)以 .co.uk 结尾的域,则脚本会将“co”作为 TLD。

在数组中检查超过 2 个字符串也不是一个选项(我认为),因为如果用户然后输入“sub.domain.com”,脚本将“sub”作为基础,“domain.com”作为顶级域名。

另外,Marcus Adams,您说如果whois 服务器显示“可用”,这并不能保证它可用,我必须查询注册商。但是我该怎么做呢?有任何想法吗?

多谢你们 :)

4

4 回答 4

1

I've implemented such code, but not in PHP. Here's what I learned.

The algorithm

Be careful because some domains can have first and second level top level domains. For example example.in and example.co.in.

I recommend first trimming the domains of leading and trailing white space and converting them to lowercase.

Since many TLDs have their own whois server, you may as well create a table or array of every possible TLD, in lower case, of course.

Then, you check to see if there is a period. If there is no period, then there's nothing further to do.

If there is a period, then you must extract the TLD. Start at left side and find the first period. Split the string there. If the right side matches one of the TLDs in the list, then everything on the left was the name and everything on the right was the TLD. If there is no TLD match, then move to the next period and repeat until you find a match or you run out of periods.

If you can't find a match, then they've not entered a valid domain. You could try splitting at the last period on the right because maybe they entered www.wiki.example.

If you find a match, you still have to see if there is another period on the left side of the split and trim there or deem it invalid.

Finding the whois server

IANA provides basic information on each TLD, including the whois server.

Root Zone Database

Note that you'll probably be creating regular expressions to evaluate the result from each whois server, as the results are not standardized.

Whois database is not the same as the registrar database

You cannot rely on a domain being available simply because the whois server reports that it's "available". In most cases it will be accurate, but don't make any promises to the user that they can register it. You must query the registrar to see if the domain is available.

The most notable exception is when a domain is about to be deleted. There is a period of up to a day where the whois server will have no record of it, but it has not yet released from the registrar.

Internationalized Domain Names

Do you plan on supporting IDNs?

于 2011-11-23T21:20:11.663 回答
1

没有算法方法可以找到可以为特定顶级域注册域的最高级别(每个注册机构的策略不同),唯一的方法是创建所有顶级域的列表和级别可以在哪些域注册。

这是公共后缀列表退出的主要原因。

使用此列表中收集的定义,您可以轻松地将域名解析为其部分,提取 TLD、域和子域。

于 2011-12-22T20:14:39.613 回答
0

The best way to check is to loop through all the possible domain extensions, split the string with explode and then check whatever comes after the dot.

This is for step 3 & 4:

function isFullDomain($domain){
    $domain=explode('.', $domain);
    foreach($possibleDomainExts as $ext){
        if($ext==$domain[count($domain)-1) return $ext;
    }
    return false;
}

call it like this:

if(!$ext=isFullDomain($domain)){
    //is only the base
}
else{
    //is the full domain and $ext will hold the value of the domain extension
}

You already have that PHP whois script, so take it apart to get a list of possible domains, and also for help with steps 5 & 6

于 2011-11-23T20:53:33.573 回答
0

我不确定是否已经存在为此的脚本,但是您提出的解决方案将起作用。

假设所有 whois 查找逻辑都在一个称为check_whois($base, $tld)解决方案的方法中,可能看起来像这样:

$pieces = explode(".", $user_input);
$base = $pieces[0];
$tld = $pieces[1];
if ($tld == null) {
  $default_tlds = array("com","net","org");
  foreach( $default_tlds as $tld ) {
    check_whois($base, $tld);
  }
} else {
  check_whois($base, $tld);
}
于 2011-11-23T21:11:40.357 回答