#!/usr/bin/env bash cache_file="/tmp/tlds-alpha-by-domain.txt" cache_duration=86400 tld_list_url="https://data.iana.org/TLD/tlds-alpha-by-domain.txt" if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi keyword=$1 fetch_tlds() { if [[ -f "$cache_file" ]]; then last_modified=$(date -r "$cache_file" +%s) current_time=$(date +%s) if ((current_time - last_modified < cache_duration)); then cat "$cache_file" return fi fi curl -s "$tld_list_url" -o "$cache_file" cat "$cache_file" } tlds=$(fetch_tlds | tail -n +2 | tr '[:upper:]' '[:lower:]') declare -A seen_tlds declare -a all_tlds generate_hacks() { local str=$1 full_domain for ((i=1; i<${#str}; i++)); do prefix=${str:0:i} suffix=${str:i} if echo "$tlds" | grep -q "^$suffix$"; then if [[ -z ${seen_tlds[$suffix]} ]]; then full_domain="$prefix.$suffix" echo "$full_domain" seen_tlds[$suffix]=1 all_tlds+=("$full_domain") fi fi done } generate_path_hacks() { local str=$1 full_domain for ((i=1; i<${#str}; i++)); do subdomain=${str:0:i} remaining=${str:i} for ((j=1; j<${#subdomain}; j++)); do prefix=${subdomain:0:j} suffix=${subdomain:j} if echo "$tlds" | grep -q "^$suffix$"; then if [[ -z ${seen_tlds[$suffix]} ]]; then if [[ -n "$remaining" && -n "$subdomain" ]]; then echo "$prefix.$suffix/$remaining" seen_tlds[$suffix]=1 all_tlds+=("$prefix.$suffix") fi fi fi done done } check_if_registered() { domain=$1 result=$(dig +short "$domain") if [ -z "$result" ]; then echo "$domain ... AVAILABLE" else echo "$domain ... REGISTERED" fi } generate_hacks "$keyword" keyword_with_s="${keyword}s" generate_hacks "$keyword_with_s" for ((i=0; i<${#keyword}; i++)); do modified_keyword="${keyword:0:i}${keyword:i+1}" generate_hacks "$modified_keyword" done generate_path_hacks "$keyword" keyword_with_s="${keyword}s" generate_path_hacks "$keyword_with_s" for ((i=0; i<${#keyword}; i++)); do modified_keyword="${keyword:0:i}${keyword:i+1}" generate_path_hacks "$modified_keyword" done echo "Checking if generated domain hacks are registered:" for domain in "${all_tlds[@]}"; do check_if_registered "$domain" done