-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblacklist-US.sh
More file actions
executable file
·56 lines (44 loc) · 1.11 KB
/
Copy pathblacklist-US.sh
File metadata and controls
executable file
·56 lines (44 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
####
SET_NAME=web-shield
FILE="./webblock-US.lst"
ALTFILE="./webblock-US.me"
if [[ -f "$ALTFILE" ]]; then
FILE=$ALTFILE
echo "Using custom list: $FILE"
fi
if [[ $1 = @(del|delete|DELETE) ]]; then
PARM="del"
else
PARM=""
fi
echo '#######'
echo '#'
if [[ $PARM == "del" ]]; then
echo -n "Removing entries from $FILE in the $SET_NAME blacklist, which contains "
else
echo -n "Adding $FILE to the $SET_NAME blacklist, which contains "
fi
echo `cat $FILE | grep '^[[:blank:]]*[^[:blank:]#;]' | wc -l` "IP blocks."
head -n 6 $FILE
read -p "Continue (Y/n)?" CONT
if [[ $CONT =~ ^(y|Y|$) ]]; then # this also accept ENTER, to default to No remove the |$
echo "Yes";
# this will not reject non proper lines - Expects: a.b.c.d/cidr
while read -r line; do
[[ "$line" =~ ^#.*$ ]] && continue
[[ "$line" =~ ^$ ]] && continue
if [[ $PARM == "del" ]]; then
echo " UN-Blacklisting ${line}"
ipset del $SET_NAME ${line}
else
echo " Blacklisting ${line}"
ipset add $SET_NAME ${line}
fi
done < "$FILE"
echo "## end."
else
echo "Operation Cancelled";
exit;
fi