检查域可用性-避免前端运行-使用通配符或正则表达式 [英] Check domain availability -- avoiding front running -- using wildcards or regex

查看:56
本文介绍了检查域可用性-避免前端运行-使用通配符或正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 whois abc123.com 检查个人域的可用性.

I can check for the availability of a an individual domain via whois abc123.com.

我不知道如何检查符合条件的整个域的可用性 ,例如 XXX YYY . Z .其中X是相同字母中的任意3个,Y是相同数字中的任意3个,Z是com,org或io中的任何一个.就像aaa111.org

I can't figure out how to check the availability of a whole set of domains that match criteria, like XXX YYY.Z. where X is any 3 of the same letters, Y is any 3 of the same numbers, and Z is any of com, org, or io. Like aaa111.org

这只是一个示例,但您了解了-我想指定字符串,模式和结尾,并查看可用的内容.

That's just an example case, but you get the idea - I'd like to specify strings, patterns, and endings, and see what's available.

我可以使用Regex进行这种字符串匹配,但是我不知道如何将其应用于Shell脚本.

I can do this kind of string matching with Regex, but I don't know how to apply that to a shell script.

我希望能够通过数组或正则表达式输入匹配条件,并输出所有匹配域的列表.

I want to be able to input my matching criteria either via an array or a regex, and output a list of all matching domains.

whois abc.com |grep"No match" 在这里很有用,因为如果未注册该域,则为空白;也许这可能会影响脚本,或者类似的东西.它还将输出减少到一行,而不是 whois 默认情况下输出的大量垃圾.

whois abc.com | grep "No match" is useful here, because it is blank if that domain is not registered; maybe that could factor into the script, or something like that. it also reduces the output to a single line, rather than the mountain of garbage that whois outputs by default.

一个适用于bash,zsh或fish的脚本将不胜感激.

A script that works either with bash, zsh, or fish would be appreciated.

您可能想知道为什么当您可以访问网站时为什么要从命令行进行此操作-原因是您要找的域经常在您实际搜索之时就被掠夺.这是一个众所周知的现象,称为域名抢先运行,而我直到今天才遇到我,因此我尝试了一种不通过注册服务商的本地自动化解决方案.

You might be wondering why bother doing this from command line when you can go to a website - the reason is that the domain you're looking for is often poached the moment you actually search for it. This is a well-known phenomenon known as domain name front running, and I had happened to me just today, hence my attempts at a local, automated solution that doesn't go through a registrar.

...

根据评论进行我并不喜欢该解决方案的"whois"方面,而只是可以通过正则表达式或模式进行检查.-事实证明,"whois"是避免误报所必需的;答案已修改为包括此方面.

Edit in response to comment: I'm not attached to the "whois" aspect of the solution, just the ability to check via regex or pattern. -- Edit 2: "whois" turned out to be necessary to avoid false positives; answer was revised to include this aspect.

推荐答案

以下是仅在没有 SOA 记录时使用DNS请求和Whois的示例实现:

Here is an example implementation using DNS requests and Whois only when no SOA record:

#!/usr/bin/env bash

for z in {com,org,io}; do
  for y in {0..9}; do
    for x in {a..z}; do

      # Compose domain as xxxyyy.z
      domain="$x$x$x$y$y$y.$z"

      # If domain has no SOA DNS record, chances are it is available.
      if [ -z "$(dig +keepopen +short -q "$domain" -t SOA)" ]; then

        # To be sure a domain without SOA DNS record is really available:
        # check it has no whois record either
        if ! whois "$domain" >/dev/null; then
          printf 'Domain %s is available\n' "$domain"
        else
          printf 'Domain %s has no DNS SOA but has a whois record\n' "$domain"
        fi
      else
        printf 'An SOA record exist for domain %s.\nIt may not be available.\n' "$domain"
      fi
    done
  done
done

对输出的第一行进行采样:

Sample first lines of output:

Domain aaa000.com has no DNS SOA but has a whois record
An SOA record exist for domain bbb000.com.
It may not be available.
An SOA record exist for domain ccc000.com.
It may not be available.
Domain ddd000.com has no DNS SOA but has a whois record
An SOA record exist for domain eee000.com.
It may not be available.
An SOA record exist for domain fff000.com.
It may not be available.
An SOA record exist for domain ggg000.com.
It may not be available.

请不要在下面执行此操作:

我不知道如何检查符合条件的整个域的可用性 ,例如 XXX YYY . Z .其中X是任意3个字母,Y是任意3个数字,Z是com,org或io中的任何一个.

I can't figure out how to check the availability of a whole set of domains that match criteria, like XXX YYY.Z. where X is any 3 letters, Y is any 3 numbers, and Z is any of com, org, or io.

原因是:这意味着要测试52728000个单个域名的可用性,请求的数量是不现实的,甚至对于DNS服务而不是Whois服务.

The reason is: it would means testing the availability of 52728000 individual domain names, an unrealistic number of requests, even for DNS services rather than Whois services.

背后的算法

  • XXX ,其中X是任意3个字母:26个字母→26×26×26 = 17576组合
  • YYY ,其中Y是任意3个数字:10个数字→10×10×10 = 1000个组合
  • Z ,其中Z是com,org或io中的任何一个:3个TLD→3个组合
  • XXX where X is any 3 letters: 26 letters → 26×26×26=17576 combinations
  • YYY where Y is any 3 numbers: 10 numbers → 10×10×10=1000 combinations
  • Z where Z is any of com, org, or io: 3 TLDs → 3 combinations

XXXYYY.Z :17576×1000×3→52728000组合

XXXYYY.Z: 17576×1000×3 → 52728000 combinations

让我们使用循环而不是整个Bash方括号表达式来生成域,因为它不适合仅使用方括号exp的内存:

Lets figure this volume of domains with using loops rather than whole Bash bracket expressions to generate them, because it would not fit into memory with bracket-exp only:

#!/usr/bin/env bash

for Z in {com,org,io}; do
  for YYY in {0..9}{0..9}{0..9}; do
    for XXX in {a..z}{a..z}{a..z}; do
      printf '%s%s.%s\n' "$XXX" "$YYY" "$Z"
    done
  done
done

这篇关于检查域可用性-避免前端运行-使用通配符或正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆