-
Notifications
You must be signed in to change notification settings - Fork 0
/
_block-ipv4-addr.sh
53 lines (46 loc) · 915 Bytes
/
_block-ipv4-addr.sh
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
#!/bin/sh
# quite-ish
E=true;
if [ "$2" = "false" ]; then
E=false;
fi;
IP=$(basename "$1");
if [ "$IP" = "" ]; then
echo "$0 127.0.0.255";
exit;
fi;
C=$(echo "$IP" | wc -c);
D=$(echo "$IP" | cut -d \. -f 4);
if [ $C -lt 7 -o -z "$D" ]; then
echo "error: not IPv4: $IP";
exit;
fi;
# IPv4 as files in directory
D="SSFWROOT/PREFIX_block-dir/ipv4";
if [ ! -d "$D" ]; then
echo "not found: $D";
exit;
fi;
cd "$D";
if [ "$(ls -1 2>/dev/null | grep $IP)" = "" ]; then
echo "$(date -Iseconds)" > $IP;
chown WWWUSER $IP;
else
B=$(cat $IP);
if [ "$B" = "" ]; then
echo "$(date -Iseconds)" > $IP;
else
$E && echo "$IP already set: $(echo $B | tr T \ )";
fi;
fi;
B=$(ip route show | grep " $IP ");
if [ "$B" = "" ]; then
ip route add blackhole $IP/32;
C="added";
B=$(ip route show | grep " $IP ");
else
C="exists";
fi;
echo "$C: $B";
$E && echo "show all: ip route show";
exit;