-
Notifications
You must be signed in to change notification settings - Fork 2
/
freenode-chooser
executable file
·90 lines (73 loc) · 2.24 KB
/
freenode-chooser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
SKIP_IPV4=false
SKIP_IPV6=false
while [[ $# -gt 0 ]]; do
case $1 in
--skip4) SKIP_IPV4=true
;;
--skip6) SKIP_IPV6=true
;;
esac
shift
done
EU_IPV6=""
EU_IPV6="$EU_IPV6 adams.freenode.net"
EU_IPV6="$EU_IPV6 calvino.freenode.net"
EU_IPV6="$EU_IPV6 cameron.freenode.net"
EU_IPV6="$EU_IPV6 gibson.freenode.net"
EU_IPV6="$EU_IPV6 hobana.freenode.net"
EU_IPV6="$EU_IPV6 holmes.freenode.net"
EU_IPV6="$EU_IPV6 leguin.freenode.net"
EU_IPV6="$EU_IPV6 lindbohm.freenode.net"
EU_IPV6="$EU_IPV6 rajaniemi.freenode.net"
EU_IPV4=""
EU_IPV4="$EU_IPV4 barjavel.freenode.net"
EU_IPV4="$EU_IPV4 hitchcock.freenode.net"
EU_IPV4="$EU_IPV4 kornbluth.freenode.net"
EU_IPV4="$EU_IPV4 pratchett.freenode.net"
EU_IPV4="$EU_IPV4 sendak.freenode.net"
EU_IPV4="$EU_IPV4 wolfe.freenode.net"
BEST_RTT="9999"
BEST_SRV="-none-"
lower_than() {
[[ $(echo "$1 < $2" | bc) == "1" ]] && return 0
return 1
}
check_srv() {
local SRV="$1"
local IPV6=""
[[ "$2" == "ipv6" ]] && IPV6="6"
echo -e -n "\rPinging $SRV ..."
local RES=$(ping$IPV6 -n -c4 "$SRV"|grep "rtt \|%")
#local RES="neco 0% nic
#uvidime 12/13.3/neco"
echo -e -n "\rTracing $SRV ..."
local HOPS=$(traceroute$IPV6 -n "$SRV"|tail -n+2|wc -l)
#local HOPS="10"
echo -e -n "\rCalculating $SRV ..."
local PKTLOSS=$(echo "$RES"|head -n1|sed "s/.* \([0-9]\+%\) .*/\1/")
if [[ $(echo "$RES"|wc -l) -lt 2 ]]; then
local AVGRTT="9999"
else
local AVGRTT=$(echo "$RES"|tail -n1|sed "s/.* [0-9\.]\+\/\([0-9\.]\+\)\/.*/\1/")
fi
echo -e -n "\rComparing $SRV ..."
if [[ "$PKTLOSS" == "0%" ]] && lower_than "$AVGRTT" "$BEST_RTT"; then
BEST_RTT="$AVGRTT"
BEST_SRV="$SRV"
[[ ! -z "$IPV6" ]] && BEST_SRV="$BEST_SRV (via IPv6)"
fi
echo -e "\r${AVGRTT} / ${PKTLOSS} loss / ${HOPS} hops => ${SRV}"
}
if ! $SKIP_IPV4; then
echo "== IPv4 servers =="
for SRV in $EU_IPV4; do check_srv "$SRV"; done
echo "== IPv6 servers via IPv4 =="
for SRV in $EU_IPV6; do check_srv "$SRV"; done
fi
if ! $SKIP_IPV6; then
echo "== IPv6 servers via IPv6 =="
for SRV in $EU_IPV6; do check_srv "$SRV" "ipv6"; done
fi
echo "== Best server is: =="
echo "$BEST_SRV with $BEST_RTT avg rtt"