sh BASH中域可用性的多线程检查程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh BASH中域可用性的多线程检查程序相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env bash
##################################################################################################################
DOMAINSAVE=""
function domain(){
read -rp "Enter JUST THE DOMAIN portion you wish to check (omitting the subdomain and TLD) . > " domainToCheck;
read -rp "Utilize custom DNS? (enter DNS or Enter to skip) > " dns;
#read -rp "Enter JUST THE DOMAIN portion you wish to check. > " domainToCheck;
if [ -z "$domainToCheck" ]; then
echo "Usage: $0 '<domain-name>' '[DNS server]'" >&2
break
fi
DOMAINSAVE=$(lcase "$domainToCheck");
touch "$DOMAINSAVE.temp"
dns="$2"
if [ -n "$dns" ]; then
echo "# Using DNS server '$dns'" >&2
save_results "# Using DNS server '$dns'" >&2
dns="@$dns"
performDNSSearch "$domainToCheck" "$dns"
else
performDNSSearch "$domainToCheck"
fi
}
function ucase(){
TC1=$(echo $1 | tr '[[:lower:]]' '[[:upper:]]' );
echo "$TC1";
}
function lcase(){
TC1=$(echo $1 | tr '[[:upper:]]' '[[:lower:]]' );
echo "$TC1";
}
function save_results(){
local lres=$(lcase "$*");
cat >> "$DOMAINSAVE.temp" << EOF
$lres
EOF
}
function check_tld() {
# $dns is not quoted so it's ignored if empty
if [ -z "$(dig +short SOA "$1" $dns)" ]; then
save_results "☑︎, $(tput setaf 2)${1}$(tput sgr0)"
else
save_results "☒, $(tput setaf 1)${1}$(tput sgr0)" >&2
fi
}
function performDNSSearch(){
tld_url="https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
echo "# Downloading TLD list from $tld_url ..." >&2
save_results "# Downloading TLD list from $tld_url ..." >&2
tlds="$(curl --progress-bar "$tld_url" | grep -v "XN--" | grep -v "^\s*#")" || (echo "Error while downloading TLDs." && save_results "Error while downloading TLDs." && exit 1)
count="$(echo "$tlds" | grep -v "xn\-\-" | wc -l)"
echo "# Getting available '$1' domains for $count TLDs ..." >&2
save_results "# Getting available '$1' domains for $count TLDs ..." >&2
workers=32
for ((i=$((workers-1)); i > 0; i--)); do
for tld in $(echo "$tlds" | awk "(NR+$i) % $workers == 0"); do
check_tld "${1}.${tld}"
done &
done
# Wait for everything to be done
wait
cat "$DOMAINSAVE.temp" | sort | grep -v "xn--" | grep -v "^\s*#" >> "$DOMAINSAVE.csv" && cat "$DOMAINSAVE.csv"
echo "# done" >&2
}
alias domain=". ~/domain.sh && domain"
以上是关于sh BASH中域可用性的多线程检查程序的主要内容,如果未能解决你的问题,请参考以下文章
C++中的多线程,只检查信号量是不是被锁定
sh Bash:检查用户是否为root
检查bash中是不是存在程序
sh BASH - 从头开始从Linux检查Linux
sh 检查Bash shell脚本中是否存在输入参数
sh 主机操作系统满足检查bash脚本的要求