-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathswi_vmnet_monitor
executable file
·90 lines (77 loc) · 2.11 KB
/
swi_vmnet_monitor
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
mkdir -p /Library/Logs/VMWareVMNETMonitor
LOG_FILE="/Library/Logs/VMWareVMNETMonitor/swi_vmnet_monitor.log"
date > $LOG_FILE
debug_echo() {
echo "$@" >> $LOG_FILE
}
debug_cat() {
cat "$@" >> $LOG_FILE
}
parse_tuns() {
debug_echo parse_tuns $1
ifconfig | grep -i "utun.: flags" | while read -r line ; do
TUN=$(echo $line | awk '{print $1;}')
TUN="${TUN%%:*}"
debug_echo parse_tuns TUN: $TUN
echo "nat on $TUN inet from $1 to any -> ($TUN) extfilter ei"
done
}
parse_netmask() {
debug_echo parse_netmask: $1 $2 $3
bits=0
for octet in $(echo $3| sed 's/\./ /g'); do
binbits=$(echo "obase=2; ibase=10; ${octet}"| bc | sed 's/0//g')
let bits+=${#binbits}
done
echo "${bits}"
}
parse_subnet() {
debug_echo parse_subnet: $1 $2 $3
echo $3
}
parse_nets() {
until [ -z $1 ]; do
debug_echo parse_nets: $1 $2 $3
NET=${2:0:6}
debug_echo parse_nets NET: $NET
shift; shift; shift
SUBNET=$(cat /Library/Preferences/VMware\ Fusion/networking | grep $NET"_HOSTONLY_SUBNET")
SUBNET=$(parse_subnet $SUBNET)
debug_echo parse_nets SUBNET: $SUBNET
NETMASK=$(cat /Library/Preferences/VMware\ Fusion/networking | grep $NET"_HOSTONLY_NETMASK")
NETMASK=$(parse_netmask $NETMASK)
parse_tuns $SUBNET/$NETMASK
done
}
reset_pfctl() {
TEMP_NAME=$(mktemp)
pfctl -a com.apple.internet-sharing/shared_v4 -s nat 2>/dev/null | grep -e "nat on" -e "no nat" | grep -v utun. > $TEMP_NAME
NATS=$(cat /Library/Preferences/VMware\ Fusion/networking | grep "_NAT yes")
debug_echo reset_pfctl
parse_nets $NATS >> $TEMP_NAME
if ifconfig | grep -q utun4; then
debug_echo "add your vpn rules here if any"
#cat /etc/pf.anchors/forwarding.vpn >> $TEMP_NAME
fi
debug_echo reset_pfctl content:
debug_cat $TEMP_NAME
pfctl -df $TEMP_NAME
pfctl -evf $TEMP_NAME
rm -f $TEMP_NAME
}
debug_echo 1
reset_pfctl
sleep 1
debug_echo 2
reset_pfctl
sleep 1
debug_echo 3
reset_pfctl
sleep 1
debug_echo 4
reset_pfctl
sleep 1
debug_echo 5
reset_pfctl
sleep 1