2018-02-22 21:32:09 +00:00
|
|
|
#!/bin/sh
|
2023-08-08 10:50:39 +00:00
|
|
|
# (c) Yannick Chabanois (ycarus@zugaina.org) for OpenMPTCProuter
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2022-02-04 19:45:15 +00:00
|
|
|
FORCEVPS=false
|
2023-08-08 10:50:39 +00:00
|
|
|
FASTTEST=false
|
2022-02-04 19:45:15 +00:00
|
|
|
if [ "$1" = "forcevps" ]; then
|
|
|
|
FORCEVPS=true
|
2021-03-26 15:03:52 +00:00
|
|
|
fi
|
2023-08-08 10:50:39 +00:00
|
|
|
if [ "$1" = "fasttest" ]; then
|
|
|
|
FASTTEST=true
|
|
|
|
fi
|
|
|
|
for i in $@; do :; done
|
|
|
|
INTERFACE="$i"
|
2023-12-13 09:57:05 +00:00
|
|
|
[ "$INTERFACE" = "forcevps" ] || [ "$INTERFACE" = "fasttest" ] && INTERFACE=""
|
2018-02-22 21:32:09 +00:00
|
|
|
|
2021-03-29 19:05:54 +00:00
|
|
|
[ -n "$INTERFACE" ] && [ ! -d "/sys/class/net/$INTERFACE" ] && {
|
2023-12-13 09:57:05 +00:00
|
|
|
echo "You must use a real interface. You wan find them using 'ip a' for example (not $INTERFACE)"
|
2021-03-29 19:05:54 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2023-08-09 19:57:11 +00:00
|
|
|
[ "$FASTTEST" = true ] || echo "Select best test server..."
|
2024-04-29 14:38:11 +00:00
|
|
|
HOSTLST="http://scaleway.testdebit.info/10G.iso http://bordeaux.testdebit.info/10G.iso http://aix-marseille.testdebit.info/10G.iso http://lyon.testdebit.info/10G.iso http://lille.testdebit.info/10G.iso http://paris.testdebit.info/10G.iso http://appliwave.testdebit.info/10G/10G.iso http://speedtest.frankfurt.linode.com/garbage.php?ckSize=10000 http://speedtest.tokyo2.linode.com/garbage.php?ckSize=10000 http://speedtest.singapore.linode.com/garbage.php?ckSize=10000 http://speedtest.newark.linode.com/garbage.php?ckSize=10000 http://speedtest.atlanta.linode.com/garbage.php?ckSize=10000 http://speedtest.dallas.linode.com/garbage.php?ckSize=10000 http://speedtest.fremont.linode.com/garbage.php?ckSize=10000 http://ipv4.bouygues.testdebit.info/10G.iso http://par.download.datapacket.com/10000mb.bin http://nyc.download.datapacket.com/10000mb.bin http://ams.download.datapacket.com/10000mb.bin http://fra.download.datapacket.com/10000mb.bin http://lon.download.datapacket.com/10000mb.bin http://mad.download.datapacket.com/10000mb.bin http://prg.download.datapacket.com/10000mb.bin http://sto.download.datapacket.com/10000mb.bin http://vie.download.datapacket.com/10000mb.bin http://war.download.datapacket.com/10000mb.bin http://atl.download.datapacket.com/10000mb.bin http://chi.download.datapacket.com/10000mb.bin http://lax.download.datapacket.com/10000mb.bin http://mia.download.datapacket.com/10000mb.bin http://nyc.download.datapacket.com/10000mb.bin http://speedtest.milkywan.fr/files/10G.iso"
|
2022-02-04 19:45:15 +00:00
|
|
|
bestping="9999"
|
|
|
|
for pinghost in $HOSTLST; do
|
|
|
|
domain=$(echo $pinghost | awk -F/ '{print $3}')
|
|
|
|
if [ -z "$INTERFACE" ] || [ "$FORCEVPS" = true ]; then
|
2023-02-18 14:41:02 +00:00
|
|
|
ping=$(ping -4 -c1 -w2 $domain | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
|
2022-02-04 19:45:15 +00:00
|
|
|
else
|
2023-02-18 14:41:02 +00:00
|
|
|
ping=$(ping -4 -c1 -w2 -I $INTERFACE -B $domain | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
|
2022-02-04 19:45:15 +00:00
|
|
|
fi
|
2023-08-09 19:57:11 +00:00
|
|
|
[ "$FASTTEST" = true ] || echo "host: $domain - ping: $ping"
|
2022-02-04 19:45:15 +00:00
|
|
|
if [ -n "$ping" ] && [ "$ping" -lt "$bestping" ]; then
|
|
|
|
bestping=$ping
|
|
|
|
HOST=$pinghost
|
|
|
|
fi
|
|
|
|
done
|
2020-10-02 15:24:02 +00:00
|
|
|
|
2024-04-29 14:38:11 +00:00
|
|
|
[ -z "$HOST" ] && HOST="http://speedtest.milkywan.fr/files/10G.iso"
|
2020-10-02 15:24:02 +00:00
|
|
|
|
2023-08-09 19:57:11 +00:00
|
|
|
[ "$FASTTEST" = true ] || echo "Best server is $HOST, running test:"
|
2018-02-22 21:32:09 +00:00
|
|
|
trap : HUP INT TERM
|
2018-07-22 20:10:30 +00:00
|
|
|
if [ -z "$INTERFACE" ]; then
|
2023-12-13 09:57:05 +00:00
|
|
|
if [ "$FASTTEST" = true ]; then
|
|
|
|
avg_speed=$(curl -4 --max-time 10 -o /dev/null -qfsS -w '%{speed_download}' $HOST 2>/dev/null)
|
|
|
|
echo "$avg_speed"
|
|
|
|
else
|
|
|
|
curl -4 -o /dev/null $HOST || echo
|
|
|
|
fi
|
2018-07-22 20:10:30 +00:00
|
|
|
else
|
2023-11-22 13:58:37 +00:00
|
|
|
[ -n "$(tc qdisc show dev $INTERFACE | grep ingress)" ] && /etc/init.d/sqm stop $INTERFACE
|
2020-10-02 15:24:02 +00:00
|
|
|
domain=$(echo $HOST | awk -F/ '{print $3}')
|
2021-01-29 16:28:57 +00:00
|
|
|
hostip=$(dig +nocmd +noall +answer A $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ')
|
2021-02-09 13:36:32 +00:00
|
|
|
if [ -n "$(ipset list 2>/dev/null | grep ss_rules)" ]; then
|
|
|
|
for ip in $hostip; do
|
|
|
|
ipset add ss_rules_dst_bypass_all $ip
|
|
|
|
done
|
|
|
|
fi
|
2024-04-03 08:16:52 +00:00
|
|
|
if [ -n "$(nft list set inet fw4 omr_dst_bypass_all_4 2>/dev/null)" ]; then
|
|
|
|
for ip in $hostip; do
|
2024-07-04 08:48:01 +00:00
|
|
|
nft add element inet fw4 omr_dst_bypass_all_4 { $ip } >/dev/null 2>&1
|
2024-04-03 08:16:52 +00:00
|
|
|
done
|
|
|
|
fi
|
2023-08-09 19:57:11 +00:00
|
|
|
if [ "$FASTTEST" = true ]; then
|
2023-08-08 10:50:39 +00:00
|
|
|
avg_speed=$(curl -4 --max-time 10 -o /dev/null -qfsS -w '%{speed_download}' --interface $INTERFACE $HOST 2>/dev/null)
|
|
|
|
echo "$avg_speed"
|
|
|
|
else
|
2023-08-09 19:57:11 +00:00
|
|
|
curl -4 -o /dev/null --interface $INTERFACE $HOST || echo
|
2023-08-08 10:50:39 +00:00
|
|
|
fi
|
2021-02-09 13:36:32 +00:00
|
|
|
if [ -n "$(ipset list 2>/dev/null | grep ss_rules)" ]; then
|
|
|
|
for ip in $hostip; do
|
|
|
|
ipset del ss_rules_dst_bypass_all $ip
|
|
|
|
done
|
|
|
|
fi
|
2024-04-03 08:16:52 +00:00
|
|
|
if [ -n "$(nft list set inet fw4 omr_dst_bypass_all_4 2>/dev/null)" ]; then
|
|
|
|
for ip in $hostip; do
|
2024-07-04 08:48:01 +00:00
|
|
|
nft delete element inet fw4 omr_dst_bypass_all_4 { $ip } >/dev/null 2>&1
|
2024-04-03 08:16:52 +00:00
|
|
|
done
|
|
|
|
fi
|
2023-08-08 19:55:28 +00:00
|
|
|
/etc/init.d/sqm start $INTERFACE
|
2018-07-22 20:10:30 +00:00
|
|
|
fi
|