1234567891011121314151617181920212223242526 |
- #!/bin/bash
- # Put your UUID here, and keep it secret!
- UUID="00000000-0000-0000-0000-000000000000"
- PEERFINDER="http://172.23.184.112:8888"
- NB_PINGS=5
- SLEEP=20
- [ -z "$1" ] && FAMILY="ipv4" || FAMILY="ipv6"
- [ "$FAMILY" = "ipv4" ] && PING="ping" || PING="ping6"
- while :
- do
- sleep "$SLEEP"
- curl "$PEERFINDER"/target/"$UUID" > /tmp/"$FAMILY" 2> /dev/null
- read -r id ip < /tmp/"$FAMILY"
- # Avoid empty fields
- [ -z "$id" -o -z "$ip" ] && continue
- # Make sure "id" is an integer
- printf "%d" "$id" > /dev/null 2>&1 || continue
- rtt="$($PING -c "$NB_PINGS" "$ip" | grep rtt | cut -d '/' -f 5)"
- [ -z "$rtt" ] && continue
- echo "RTT to target $id ($ip) is $rtt"
- curl -d "target=${id}&rtt=${rtt}" "$PEERFINDER"/result/report/"$UUID"
- done
|