-
Notifications
You must be signed in to change notification settings - Fork 65
/
awareness.sh
90 lines (73 loc) · 1.83 KB
/
awareness.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
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
# -----
# Name: nac_bypass_setup.sh
# scip AG - Michael Schneider
# -----
## Variables
VERSION="0.1.0"
INTERFACE="eth0"
STATE_INTERFACE=0
STATE_COUNTER=0
THRESHOLD_UP=3
THRESHOLD_DOWN=5
TIMER="5s"
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
## display usage hints
Usage() {
echo -e "$0 v$VERSION usage:"
echo " -h display this help"
echo " -i <eth> network interface plugged into switch"
exit 0
}
## display version info
Version() {
echo -e "$0 v$VERSION"
exit 0
}
## Check if we got all needed parameters
CheckParams() {
while getopts ":hi:" opts
do
case "$opts" in
"i")
INTERFACE=$OPTARG
;;
"h")
Usage
;;
*)
INTERFACE="eth0"
;;
esac
done
}
## Main
CheckParams $@
## Run Initial Configuration
bash "${SCRIPT_DIR}/nac_bypass_setup.sh" -a -i
## Loop
while true
do
NETWORK_STATE_INTERFACE=`cat "/sys/class/net/$INTERFACE/carrier"`
if [ "$NETWORK_STATE_INTERFACE" -ne "$STATE_INTERFACE" ]; then
STATE_COUNTER=0
if [ "$NETWORK_STATE_INTERFACE" -eq 1 ]; then
echo "[!] $INTERFACE is now up!"
else
echo "[!] $INTERFACE is now down!"
fi
else
if [ "$STATE_COUNTER" -eq "$THRESHOLD_UP" ] && [ "$NETWORK_STATE_INTERFACE" -eq 1 ]; then
echo "[!!] Set new config"
bash "${SCRIPT_DIR}/nac_bypass_setup.sh" -a -c
elif [ "$STATE_COUNTER" -eq "$THRESHOLD_DOWN" ] && [ "$NETWORK_STATE_INTERFACE" -eq 0 ]; then
echo "[!!] Reset config"
bash "${SCRIPT_DIR}/nac_bypass_setup.sh" -a -r
bash "${SCRIPT_DIR}/nac_bypass_setup.sh" -a -i
fi
echo "[*] Waiting"
((STATE_COUNTER++))
fi
STATE_INTERFACE=$NETWORK_STATE_INTERFACE
sleep $TIMER
done