Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$ sudo mkdir /etc/pf-files
In /etc/pf.conf the following needs to be added:
1. In the prerequisites-section add:
table <blocked_zones> persist file "/etc/pf-files/blocked_zones"
2. In the block-section add early:
block in quick proto tcp from <blocked_zones> to any port { 22 80 }
blocn_traffic.sh
#! /bin/sh
# Purpose: Block all traffic from specific countries. Use ISO code. #
PF_DIR=/etc/pf-files
ZONE_FILE=blocked_zones
touch ${ZONE_FILE}
for i in cn az by kz kg ru tj tm uz vn kr se th
do
wget -4 --no-proxy --no-cookies --no-cache \
http://ipdeny.com/ipblocks/data/countries/$i.zone
cat $i.zone >> ${ZONE_FILE}
sleep 2
done
#
rm *.zone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment