This repository has been archived on 2024-03-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
adlin/ping-checker.sh

48 lines
967 B
Bash
Executable file

#!/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