检查用户是否输入了域名或仅输入了基数

发布于 2024-12-17 20:04:27 字数 1362 浏览 1 评论 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. 如果用户输入完整域名,请将基本域名和 TLD 分开,并将它们都存储在变量中,并将“状态”存储在某处 ($full = true/false)
  5. if ($full = true) {check相应的 whois 服务器$base.com $base.net 等};
  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 服务器显示“可用”,这并不能保证它可用,我必须查询注册商。但我该怎么办呢?有什么想法吗?

谢谢大家:)

I want to create something that does a WHOIS query to see if a domain is available. Now, I've found quite a bunch of ready-made scripts for that, but they all seem to be the same in that you need to specify the base, and then choose which extensions you want and it will do that (so for example, enter 'test', check .com and it will check if test.com is available)

However, I'm trying to do something slightly else. The thing I want it to do is check if the user has entered just the base or the full URL, and then do one or multiple queries accordingly. Example:

If the user enters 'test', I want the script to check for test.com, test.org, test.net, etc.
If the user enters 'test.com', I want the script to check JUST for test.com.

I really don't know what to build upon, but Mike Nott's PHP Whois Script looks okay. Of course, suggestions are always welcome.

Now I'm guessing the script flow should go something like this:

  1. User enters query
  2. Script checks for spaces
  3. Script checks if user entered just a base or a full domain name (I'm guessing the way to go about this is to check if there's a dot in there)
  4. If the user entered a full domain name, separate the base and the TLD and store them both in variables and store the 'status' somewhere ($full = true/false)
  5. if ($full = true) {check corresponding whois servers for $base.com $base.net, etc};
  6. if ($full != true) {see what the right server for $tld is and check that one for $base.$tld}
  7. Output results

Of course, if there's a script that does this already, let me know.

Edit: Just so you know, I can do simple if statements and the likes, but steps 3, 4, 5 and 6 in my 'workflow' are the parts I can't figure out.

Edit 2: Thanks for all of your answers, guys! Marcus Adam's theories are indeed valid. My domain reseller (the guys I'm getting my domains from) doesn't offer second-level TLD's like .co.uk though, so that's not a problem. They also don't support IDNs.

From the answers of you guys, I came to the conclusion that the explode function is used to separate the domain name. However, what will explode do when it encounters multiple dots? I'm guessing it'll just add another entry to the array, but that will cause problems. Because if the user then enters (for example) a domain ending in .co.uk, the script will take 'co' as the TLD.

Checking for more than 2 strings in the array is also not an option (I think), because if the user then enters 'sub.domain.com' the script will take 'sub' as the base and 'domain.com' as the TLD.

Also, Marcus Adams, you say that if the whois server shows 'available', that's not a guarantee it's available and I must query the registrar. But how would I go about that? Any ideas?

Thanks guys :)

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

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

发布评论

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

评论(4

半窗疏影 2024-12-24 20:04:27

我已经实现了这样的代码,但不是用 PHP 实现的。这是我学到的。

算法

请小心,因为某些域可能具有第一级和第二级顶级域。例如 example.inexample.co.in

我建议首先修剪前导和尾随空格的域并将它们转换为小写。

由于许多 TLD 都有自己的 whois 服务器,因此您也可以为每个可能的 TLD 创建一个表或数组,当然,请使用小写字母。

然后,检查是否有月经。如果没有月经,那么就没有什么可做的。

如果有句点,则必须提取 TLD。从左侧开始找到第一个周期。在那里分割字符串。如果右侧与列表中的 TLD 之一匹配,则左侧的所有内容都是名称,右侧的所有内容都是 TLD。如果没有 TLD 匹配,则移至下一个周期并重复,直到找到匹配项或用完周期。

如果您找不到匹配项,则表明他们没有输入有效的域。您可以尝试在右侧的最后一个句点进行拆分,因为可能他们输入了 www.wiki.example

如果找到匹配项,您仍然需要查看拆分左侧是否还有另一个句点并修剪那里或认为它无效。

查找 whois 服务器

IANA 提供每个 TLD 的基本信息,包括 whois 服务器。

根区数据库

请注意,您可能会创建正则表达式来评估每个的结果whois 服务器,因为结果未标准化。

Whois 数据库与注册商数据库不同

您不能仅仅因为 whois 服务器报告域“可用”就认为该域可用。在大多数情况下,它是准确的,但不要向用户做出任何可以注册的承诺。您必须向注册商查询该域名是否可用。

最值得注意的例外是当域即将被删除时。在长达一天的时间内,whois 服务器不会有任何记录,但尚未从注册商处发布。

国际化域名

您计划支持IDN吗?

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?

黄昏下泛黄的笔记 2024-12-24 20:04:27

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

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

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

There is no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain (the policies differ with each registry), the only method is to create a list of all top-level domains and the level at which domains can be registered.

This is the main reason why the Public Suffix List exits.

Using the definitions collected in this list you can easily parse a domain name into its parts, extracting the TLD, the domain and the subdomain.

银河中√捞星星 2024-12-24 20:04:27

最好的检查方法是循环遍历所有可能的域扩展,用explode分割字符串,然后检查点后面的内容。

这是针对步骤 3 和 3 的。 4:

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

这样调用:

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

您已经有了 PHP whois 脚本,因此将其拆开以获得可能的域列表,并获取有关步骤 5 和 5 的帮助。 6

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

画中仙 2024-12-24 20:04:27

我不确定是否已经存在用于此目的的脚本,但您提出的解决方案将有效。

假设所有 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);
}

I'm not sure if a script already exists for this, but your proposed solution will work.

Assuming all of the whois lookup logic is in a method called check_whois($base, $tld) the solution might look something like this:

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