this is tuto1
This commit is contained in:
parent
9eaa2bf4e8
commit
9262917553
19 changed files with 928 additions and 68 deletions
48
ping-checker.sh
Executable file
48
ping-checker.sh
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ -n "$SECRET_KEY" ] || { echo "Please define SECRET_KEY"; exit 1; }
|
||||
|
||||
CNT=$(curl -s https://adlin.nemunai.re/api/ips)
|
||||
|
||||
|
||||
# First, generate static ARP table
|
||||
|
||||
echo "${CNT}" | jq -r '. | keys | .[]' - | while read sid
|
||||
do
|
||||
MAC=$(echo "${CNT}" | jq -r '.["'$sid'"].mac' -)
|
||||
if [ -n "$MAC" ]
|
||||
then
|
||||
echo "${CNT}" | jq -r '.["'$sid'"].vlan0,.["'$sid'"].vlan7' - | while read IP
|
||||
do
|
||||
arp -s "${IP}" "${MAC}"
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Then, perform checks
|
||||
|
||||
echo "${CNT}" | jq -r '. | keys | .[]' - | while read sid
|
||||
do
|
||||
IP=$(echo "${CNT}" | jq -r '.["'$sid'"].vlan0' -)
|
||||
if [ -n "${IP}" ]
|
||||
then
|
||||
case $(($sid % 5)) in
|
||||
1)
|
||||
PAT=baaaaaad;;
|
||||
2)
|
||||
PAT=baadfood;;
|
||||
3)
|
||||
PAT=baddcafe;;
|
||||
4)
|
||||
PAT=cafebabe;;
|
||||
*)
|
||||
PAT=deadbeef;;
|
||||
esac
|
||||
|
||||
arping -I br-ext -c 1 -w 1 "${IP}" && {
|
||||
ping -c 1 -w 1 -p "${PAT}" "${IP}" &
|
||||
curl -k -X POST -d '{"token": "'${SECRET_KEY}'"}' "https://172.23.200.1/api/students/$sid/pong"
|
||||
}
|
||||
fi
|
||||
done
|
Reference in a new issue