home · login to get plonkin'

domainhacks generator

@oppi.li · 3d ago · plaintext · 101 loc · raw · 2 comments

1#!/usr/bin/env bash23cache_file="/tmp/tlds-alpha-by-domain.txt"4cache_duration=864005tld_list_url="https://data.iana.org/TLD/tlds-alpha-by-domain.txt"67if [ -z "$1" ]; then8  echo "Usage: $0 <keyword>"9  exit 110fi1112keyword=$11314fetch_tlds() {15  if [[ -f "$cache_file" ]]; then16    last_modified=$(date -r "$cache_file" +%s)17    current_time=$(date +%s)18    if ((current_time - last_modified < cache_duration)); then19      cat "$cache_file"20      return21    fi22  fi2324  curl -s "$tld_list_url" -o "$cache_file"25  cat "$cache_file"26}2728tlds=$(fetch_tlds | tail -n +2 | tr '[:upper:]' '[:lower:]')2930declare -A seen_tlds31declare -a all_tlds3233generate_hacks() {34  local str=$1 full_domain35  for ((i=1; i<${#str}; i++)); do36    prefix=${str:0:i}37    suffix=${str:i}38    if echo "$tlds" | grep -q "^$suffix$"; then39      if [[ -z ${seen_tlds[$suffix]} ]]; then40        full_domain="$prefix.$suffix"41        echo "$full_domain"42        seen_tlds[$suffix]=143        all_tlds+=("$full_domain")44      fi45    fi46  done47}4849generate_path_hacks() {50  local str=$1 full_domain51  for ((i=1; i<${#str}; i++)); do52    subdomain=${str:0:i}53    remaining=${str:i}54    for ((j=1; j<${#subdomain}; j++)); do55      prefix=${subdomain:0:j}56      suffix=${subdomain:j}57      if echo "$tlds" | grep -q "^$suffix$"; then58        if [[ -z ${seen_tlds[$suffix]} ]]; then59          if [[ -n "$remaining" && -n "$subdomain" ]]; then60            echo "$prefix.$suffix/$remaining"61            seen_tlds[$suffix]=162            all_tlds+=("$prefix.$suffix")63          fi64        fi65      fi66    done67  done68}6970check_if_registered() {71  domain=$172  result=$(dig +short "$domain")73  if [ -z "$result" ]; then74    echo "$domain ... AVAILABLE"75  else76    echo "$domain ... REGISTERED"77  fi78}798081generate_hacks "$keyword"82keyword_with_s="${keyword}s"83generate_hacks "$keyword_with_s"84for ((i=0; i<${#keyword}; i++)); do85  modified_keyword="${keyword:0:i}${keyword:i+1}"86  generate_hacks "$modified_keyword"87done8889generate_path_hacks "$keyword"90keyword_with_s="${keyword}s"91generate_path_hacks "$keyword_with_s"92for ((i=0; i<${#keyword}; i++)); do93  modified_keyword="${keyword:0:i}${keyword:i+1}"94  generate_path_hacks "$modified_keyword"95done9697echo "Checking if generated domain hacks are registered:"98for domain in "${all_tlds[@]}"; do99  check_if_registered "$domain"100done101

comments

@oppi.li · 3d ago

λ ./hacks.sh oppili
oppi.li
oppil.is
opp.il/i
Checking if generated domain hacks are registered:
oppi.li ... REGISTERED
oppil.is ... AVAILABLE
opp.il ... AVAILABLE

@oppi.li · 3d ago

needs `dig`

λ nix shell nixpkgs#dig

login to post a comment