-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpn-checker.sh
61 lines (54 loc) · 1.71 KB
/
vpn-checker.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
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "run as root"
exit 1
fi
if [ -z "$1" ]; then
app_name='nekoray' # Default value when no argument is provided
else
app_name="$1"
fi
RED_COLOR_CODE='\033[0;31m'
BLUE_COLOR_CODE='\033[0;34m'
TRANSPARENT='\033[0m'
echo "START CHECKING $app_name"
osname=$(uname -s);
if [ "$osname" = "Darwin" ]; then
while(true) do
have_connection=$(scutil --nc list | grep FoXray | grep Connected)
wifi=$(networksetup -getairportnetwork en0 | grep "You are not" )
if [ -z "$wifi" ]; then
wifi_status="enabled"
else
wifi_status="disabled"
fi
current_date=$(date)
if [ -z "$have_connection" ]; then
networksetup -setairportpower en0 off
exit
echo "WIFI turned OFF ${current_date}"
elif [ "$wifi_status" = "disabled" ]; then
networksetup -setairportpower en0 on
echo -e "WIFI turned ${RED_COLOR_CODE}ON ${TRANSPARENT}${current_date}";
else
echo -e "WIFI is still ${BLUE_COLOR_CODE}ON ${TRANSPARENT}"
fi
sleep 0.1
done
else
while(true) do
have_connection=$(nmcli con show --active | grep "$app_name");
wifi_status=$(nmcli radio wifi);
current_date=$(date)
if [ -z "$have_connection" ]; then
nmcli radio wifi off
echo "WIFI turned OFF ${current_date}"
elif [ "$wifi_status" = "disabled" ]; then
nmcli radio wifi on
echo -e "WIFI turned ${RED_COLOR_CODE}ON ${TRANSPARENT}${current_date}";
else
echo -e "WIFI is still ${BLUE_COLOR_CODE}ON ${TRANSPARENT}"
fi
sleep 0.1
done
fi