Skip to content

Instantly share code, notes, and snippets.

@jsarenik
Last active December 13, 2020 18:52
Show Gist options
  • Save jsarenik/d393ca10f3c96f731fbaa78900cd856b to your computer and use it in GitHub Desktop.
Save jsarenik/d393ca10f3c96f731fbaa78900cd856b to your computer and use it in GitHub Desktop.
Yggdrasil public-peers select
#!/bin/sh
#
# Place this script into public-peers/scripts/select.sh
# chmod a+x public-peers/scripts/select.sh
# Run: cd public-peers/scripts; ./select.sh
PING=ping
printem() {
find .. -mindepth 2 -type f -name '*.md' \
| xargs cat \
| grep -o 'tcp://[^`]*' \
> /tmp/ygg-hosts
cat /tmp/ygg-hosts \
| sed 's|^tcp://||;s/:[0-9]\+$//' \
| tr -d '[]'
}
printem | while read mirror
do
(
host=`echo $mirror |sed s,.*//,,|sed s,/.*,,`
# Old systems need ping6 for IPv6
echo $host | grep -q : && PING=ping6
echo -e `$PING -c1 $host | grep time=|sed s,.*time=,,`:' \t\t'$mirror
) &
done 2>/dev/null \
| grep ^[0-9] \
| sort -n \
| head -20 \
| while read a b host; do grep "$host" /tmp/ygg-hosts; done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment