Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created October 13, 2025 15:54
Show Gist options
  • Select an option

  • Save stefanpejcic/ba3dc86135f4e284b729629d5b83685e to your computer and use it in GitHub Desktop.

Select an option

Save stefanpejcic/ba3dc86135f4e284b729629d5b83685e to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
# Usage: bash csf_drop_country_from_deny_list.sh "<country-pattern>"
# Examples: "RS/Serbia" "RS" "Serbia"
if [ $# -lt 1 ]; then
echo "Usage: $0 <country-pattern>"
exit 1
fi
COUNTRY="$1"
LOOP_WAIT=1
DENYFILE="/etc/csf/csf.deny"
if [ ! -r "$DENYFILE" ]; then
echo "Ne mogu da ocitam $DENYFILE"
exit 2
fi
grep -i -- "$COUNTRY" "$DENYFILE" \
| awk '{print $1}' \
| egrep -o '^([0-9]{1,3}\.){3}[0-9]{1,3}$' \
| while read -r ip; do
echo "Remove: $ip"
csf -dr "$ip" || echo "Upozorenje: csf -dr vrati pogresku za $ip"
sleep "$LOOP_WAIT"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment