Posted By

alexsancho on 12/05/11


Tagged

Bash domain dig Availability


Versions (?)

Checks if domain is registered


 / Published in: Bash
 

Helper to cheek if a given domain is available for registration. If tld is omitted the script uses a predefined tld array to check multiple domains.

To use copy the code to a standalone file, call it whatever you wants and make it executable (+x)

  1. #!/usr/bin/env bash
  2. # *********************************************************
  3. # file: dns
  4. # date: 18.10.2011
  5. # author: (c) by Alex Sancho - <[email protected]>
  6. # description: Checks domain availability.
  7. # *********************************************************
  8.  
  9. function usage()
  10. {
  11. prname=$(basename $0)
  12. log "\t$prname: checks domain availability"
  13. log "\tUsage: $prname <domain>"
  14. log "\tExamp: $prname example.com"
  15. }
  16.  
  17. function _main_()
  18. {
  19. if [[ "$1" == '-h' || "$1" == '--help' ]]; then
  20. usage
  21. exit 0
  22. else
  23. local domain=${1}
  24. local tld=${domain##*.}
  25.  
  26. if [[ "$tld" = "$domain" ]]; then
  27. DOMAINS=('.com' '.com.es' '.cat' '.net' '.info' '.mobi' '.org' '.tel' '.biz' '.tv' '.cc' '.eu' '.es')
  28. ELEMENTS=${#DOMAINS[@]}
  29.  
  30. for (( i=0;i<$ELEMENTS;i++)); do
  31. dig soa $domain${DOMAINS[${i}]} | grep -q ^$domain${DOMAINS[${i}]} && echo "$domain${DOMAINS[${i}]} Registered" || echo "$domain${DOMAINS[${i}]} Available"
  32. done
  33. else
  34. dig soa $domain | grep -q ^$domain && echo "$domain Registered" || echo "$domain Available"
  35. fi
  36. fi
  37. }
  38.  
  39. ## Run script...
  40. _main_ "$@"

Report this snippet  

You need to login to post a comment.