-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblock-china.sh
executable file
·50 lines (45 loc) · 1.18 KB
/
block-china.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
#!/bin/bash
# List of Chinese IP ranges
declare -a ip_ranges=(
"36.0.0.0/8"
"39.0.0.0/8"
"42.0.0.0/8"
"58.0.0.0/8"
"59.0.0.0/8"
"60.0.0.0/8"
"61.0.0.0/8"
"101.0.0.0/8"
"103.0.0.0/8"
"106.0.0.0/8"
"110.0.0.0/8"
"111.0.0.0/8"
"112.0.0.0/8"
"113.0.0.0/8"
"114.0.0.0/8"
"115.0.0.0/8"
"116.0.0.0/8"
"117.0.0.0/8"
"118.0.0.0/8"
"119.0.0.0/8"
"120.0.0.0/8"
"121.0.0.0/8"
"122.0.0.0/8"
"123.0.0.0/8"
"124.0.0.0/8"
"125.0.0.0/8"
"202.0.0.0/8"
"203.0.0.0/8"
)
# Loop through the IP ranges and add iptables rules to block inbound and outbound traffic
for ip_range in "${ip_ranges[@]}"
do
# Block inbound traffic
sudo iptables -A INPUT -s $ip_range -j DROP
echo "Blocked inbound traffic from IP range: $ip_range"
# Block outbound traffic
sudo iptables -A OUTPUT -d $ip_range -j DROP
echo "Blocked outbound traffic to IP range: $ip_range"
done
# Add connection limit rule on port 12392
sudo iptables -A INPUT -p tcp --syn --dport 12392:12392 -m connlimit --connlimit-above 15 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
echo "Connection limit rule added on port 12392"