-
Notifications
You must be signed in to change notification settings - Fork 23
/
jb.sh
65 lines (55 loc) · 1.68 KB
/
jb.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
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Function to reload pf rules on macOS
reload_pf() {
sudo pfctl -f "$PF_CONF"
sudo pfctl -e
}
# Function to handle firewall rules on Linux
handle_linux() {
result=$(sudo iptables -S | grep "block jb")
if [[ ! -z $result ]]; then
echo "Found old IP"
ip=$(echo $result | awk '{print $4}')
echo $ip
sudo iptables -D INPUT -s $ip -m comment --comment "block jb" -j DROP
echo "Deleted old IP"
fi
ipaddresses=$(dig +short account.jetbrains.com)
temp=()
for i in $ipaddresses; do temp+=($i); done
for ipaddress in ${temp[@]}; do
echo $ipaddress
sudo iptables -A INPUT -s $ipaddress -j DROP -m comment --comment "block jb"
done
echo "All good"
}
# Function to handle firewall rules on macOS
handle_macos() {
PF_CONF="/etc/pf.conf"
result=$(sudo pfctl -sr | grep "block drop from any to any")
if [[ ! -z $result ]]; then
echo "Found old IP"
ip=$(echo $result | awk '{print $7}')
echo $ip
sudo pfctl -t blocklist -T delete $ip
echo "Deleted old IP"
fi
ipaddresses=$(dig +short account.jetbrains.com)
temp=()
for i in $ipaddresses; do temp+=($i); done
for ipaddress in ${temp[@]}; do
echo $ipaddress
echo "block drop from any to $ipaddress" | sudo tee -a "$PF_CONF"
done
reload_pf
echo "All good"
}
# Detect the operating system and run the appropriate function
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
handle_linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
handle_macos
else
echo "Unsupported operating system: $OSTYPE"
exit 1
fi