Skip to content

Instantly share code, notes, and snippets.

@bing0o
Created March 22, 2020 12:15
Show Gist options
  • Select an option

  • Save bing0o/0614ed86e2b5fb3fd24db693ca042f0e to your computer and use it in GitHub Desktop.

Select an option

Save bing0o/0614ed86e2b5fb3fd24db693ca042f0e to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# cat ips | xargs -I% sh -c "host %"
# -z True if it's a zero | -n True if it's not a zero!
#
PRG=${0##*/}
Usage() {
while read -r info; do
printf "%b\n" "$info"
done <<-EOF
\rSyntax: $PRG -l [IPs/DOMAINS] -o [OutPut] [-v]
\r
\rOptions:
\r -h, --help - Displays this
\r -l, --list - List of Domains ot IPs
\r -o, --output - OutPut File
\r -v, --verbose - Displays the current position of the Testing (Default:False)
\rExample:
\r $PRG -l domains.txt -o aws.txt -v
\r
EOF
}
list=False
out=False
ver=False
while [ -n "$1" ]; do
case $1 in
-l|--list)
[ -z $2 ] && { printf "The Argumant -l/--list, Asks for a Value!\n\n"; Usage; exit 1; }
list=$2
shift ;;
-o|--output)
[ -z $2 ] && { printf "The Argumant -o/--output, Asks for a Value!\n\n"; Usage; exit 1; }
out=$2
shift ;;
-v|--verbose)
ver=True;;
-h|--help)
Usage
exit 0 ;;
esac
shift
done
[ $list == False ] && { Usage; exit 1; }
[ $out != False ] && rm $out 2>/dev/null
lines=$(wc -l < $list)
c=1
while read line; do
[ $ver == True ] && { echo -ne "[$c/$lines] $line \r"; let c=c+1; }
result=$(host $line | awk '/amazonaws.com.$/ {gsub(/\.$/,"",$NF); print $1 " | " $NF}')
[ -n "$result" ] && {
echo $result
if [[ $out != False ]]; then
echo $result >> $out
fi
}
done < $list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment