-
Notifications
You must be signed in to change notification settings - Fork 22
/
tldhunt.sh
executable file
·93 lines (82 loc) · 2.53 KB
/
tldhunt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Color definitions
: "${blue:=\033[0;34m}"
: "${cyan:=\033[0;36m}"
: "${reset:=\033[0m}"
: "${red:=\033[0;31m}"
: "${green:=\033[0;32m}"
: "${orange:=\033[0;33m}"
: "${bold:=\033[1m}"
: "${b_green:=\033[1;32m}"
: "${b_red:=\033[1;31m}"
: "${b_orange:=\033[1;33m}"
# Default value
nreg=false
# Check if whois is installed
command -v whois &> /dev/null || { echo "whois not installed. You must install whois to use this tool." >&2; exit 1; }
# Banner
cat << "EOF"
_____ _ ___ _ _ _
|_ _| | | \| || |_ _ _ _| |_
| | | |__| |) | __ | || | ' \ _|
|_| |____|___/|_||_|\_,_|_||_\__|
Domain Availability Checker
EOF
usage() {
echo "Usage: $0 -k <keyword> [-e <tld> | -E <tld-file>] [-x]"
echo "Example: $0 -k linuxsec -E tlds.txt"
exit 1
}
# Argument parsing
while [[ "$#" -gt 0 ]]; do
case $1 in
-k|--keyword) keyword="$2"; shift ;;
-e|--tld) tld="$2"; shift ;;
-E|--tld-file) exts="$2"; shift ;;
-x|--not-registered) nreg=true ;;
*) echo "Unknown parameter passed: $1"; usage ;;
esac
shift
done
# Validate arguments
[[ -z $keyword ]] && { echo "Keyword is required."; usage; }
[[ -n $tld && -n $exts ]] && { echo "You can only specify one of -e or -E options."; usage; }
[[ -z $tld && -z $exts ]] && { echo "Either -e or -E option is required."; usage; }
[[ -n $exts && ! -f $exts ]] && { echo "TLD file $exts not found."; usage; }
# Load TLDs
tlds=()
if [[ -n $exts ]]; then
readarray -t tlds < "$exts"
else
tlds=("$tld")
fi
# Function to check domain availability
check_domain() {
local domain="$1"
local whois_output
whois_output=$(whois "$domain" 2>/dev/null)
local result
result=$(echo "$whois_output" | grep -iE "Name Server|nserver|nameservers|status: active")
if [[ -n $result ]]; then
if [[ "$nreg" = false ]]; then
local expiry_date
expiry_date=$(echo "$whois_output" | grep -iE "Expiry Date|Expiration Date|Registry Expiry Date" | grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2}' | uniq)
if [[ -n $expiry_date ]]; then
echo -e "[${b_red}taken${reset}] $domain - Exp Date: ${orange}$expiry_date${reset}"
else
echo -e "[${b_red}taken${reset}] $domain - No expiry date found"
fi
fi
else
echo -e "[${b_green}avail${reset}] $domain"
fi
}
# Process TLDs
for ext in "${tlds[@]}"; do
domain="$keyword$ext"
check_domain "$domain" &
if (( $(jobs -r -p | wc -l) >= 30 )); then
wait -n
fi
done
wait