-
Notifications
You must be signed in to change notification settings - Fork 11
/
net-partition
executable file
·53 lines (46 loc) · 1.36 KB
/
net-partition
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
#!/bin/bash
# Use this to turn on or off blocking network traffic to IP address 127.0.0.2.
usage() {
echo "Usage: $0 [on|off] - Turn on or off blocking network traffic to IP 127.0.0.2." ; exit 1
}
partitionOn() {
if hash pfctl 2>/dev/null; then
(pfctl -sr 2>/dev/null; echo "block drop quick proto tcp from 127.0.0.1 to 127.0.0.2") | pfctl -f - 2>/dev/null
echo "Create partition between IP 127.0.0.1 and 127.0.0.2 (OSX)"
elif hash iptables 2>/dev/null; then
iptables -A INPUT -p tcp -s 127.0.0.1 -d 127.0.0.2 -j DROP
echo "Create partition between IP 127.0.0.1 and 127.0.0.2 (Linux)"
else
echo "This command is currently only available on OSX or Linux systems."
usage
fi
}
partitionOff() {
if hash pfctl 2>/dev/null; then
pfctl -f /etc/pf.conf 2>/dev/null
echo "Drop partition between IP 127.0.0.1 and 127.0.0.2 (OSX)"
elif hash iptables 2>/dev/null; then
iptables -D INPUT -p tcp -s 127.0.0.1 -d 127.0.0.2 -j DROP
echo "Drop partition between IP 127.0.0.1 and 127.0.0.2 (Linux)"
else
echo "This command is currently only available on OSX or Linux systems."
usage
fi
}
if ! [ $(id -u) = 0 ]; then
echo "Root user (sudo) required."
exit 1
fi
arg=$1
case $arg in
"on")
partitionOn
;;
"off")
partitionOff
;;
*)
echo "Invalid subcommand '$arg', must be 'on' or 'off'"
usage
;;
esac