Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -eq 0 ]; then
- echo "You must provide at least one ASN (multiple should be separated by space)."
- exit 0
- fi
- result=""
- dir="/etc/nginx/custom/"
- if [ ! -d "$dir" ]; then
- read -p "'$dir' does not exist. Create it? (y/n): " -n 1 -r
- echo
- if [[ $REPLY =~ ^[Yy]$ ]]; then
- mkdir -p $dir 2>/dev/null || { echo "Could not create directory. Exiting."; exit -1; }
- fi
- fi
- re='^[0-9]+$' # simple regex to make sure that each ASN is a number
- for arg in "$@"; do
- arg=$(sed 's/[AaSs]//g' <<< $arg)
- if [[ $arg =~ $re ]]; then
- result=$(whois -h whois.radb.net -- "-i origin AS${arg}" | grep -Eo "([0-9.]+){4}/[0-9]+")
- #result="$result $temp"
- read -p "Output this ASN to Nginx Blockfile? (y/N): " -n 1 -r
- echo
- if [[ $REPLY =~ ^[Yy]$ ]]; then
- for res in $result; do
- echo -e " deny $res;" >> ${dir}AS${arg}.asn 2>/dev/null || { echo "Could not write to file '${dir}AS${arg}.asn'. Exiting."; exit -1; }
- done
- fi
- for res in $result; do
- echo $res
- done
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement