run.sh 768 B

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