Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ a shared Git repository so names do not get reused:
$ git add wordlist
$ git commit
$ git push

### Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `GENHOST_DOMAIN` | The domain name to append to generated hostnames | example.com |
| `GENHOST_WORDLIST` | Filename of the word list to use, relative to genhost directory | wordlist |

$ export GENHOST_DOMAIN=github.com
$ ./genhost 3
cover.github.com
kilo.github.com
open.github.com

$ export GENHOST_WORDLIST=colors.txt
$ ./genhost 1
yellow.github.com
15 changes: 13 additions & 2 deletions genhost
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
# genhost - generate unused hostnames by randomly picking from a word list
#

readonly wordlist='wordlist'
# script path variables
readonly script=$(realpath $0)
readonly script_name=$(basename $script)
readonly script_dir=$(dirname $script)

readonly wordlist=${GENHOST_WORDLIST:-wordlist}
readonly domain=${GENHOST_DOMAIN:-example.com}

# validate path to word list file
if [[ "$wordlist" == *".."* ]] || [ "$(basename $wordlist)" == "$script_name" ]; then
printf 'genhost: invalid word list file: %s\n' $wordlist
exit 1
fi

# http://mywiki.wooledge.org/BashFAQ/026

# returns random number from 0 to ($1-1) in global var 'r'.
Expand Down Expand Up @@ -75,7 +86,7 @@ else
;;
esac
elif [[ $1 == "list" ]]; then
grep "#" wordlist | sed 's/#//'
grep "#" "$wordlist" | sed 's/#//'
else
printf 'genhost: invalid input\n' >&2
exit 1
Expand Down