mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Fix omr-speedtest
This commit is contained in:
parent
8b39370e9b
commit
7bd47e4502
1 changed files with 90 additions and 18 deletions
|
@ -1,35 +1,107 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (C) 2018-2024 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
|
||||||
|
#
|
||||||
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
|
# See /LICENSE for more information.
|
||||||
|
#
|
||||||
|
# This script check speed using Speedtest servers
|
||||||
|
|
||||||
INTERFACE="$1"
|
INTERFACE="$1"
|
||||||
|
|
||||||
|
bypass_host_enable() {
|
||||||
|
INTERFACE=$1
|
||||||
|
HOST=$2
|
||||||
|
[ -n "$(tc qdisc show dev $INTERFACE | grep ingress)" ] && /etc/init.d/sqm stop $INTERFACE
|
||||||
|
domain=$(echo $HOST | awk -F/ '{print $3}')
|
||||||
|
if [ "$IPV6" = true ]; then
|
||||||
|
hostip=$(dig +nocmd +noall +answer AAAA $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ')
|
||||||
|
if [ -n "$(ipset list 2>/dev/null | grep ss_rules6)" ]; then
|
||||||
|
for ip in $hostip; do
|
||||||
|
ipset add ss_rules6_dst_bypass_all $ip
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ -n "$(nft list set inet fw4 omr_dst_bypass_all_6 2>/dev/null)" ]; then
|
||||||
|
for ip in $hostip; do
|
||||||
|
nft add element inet fw4 omr_dst_bypass_all_6 { $ip } >/dev/null 2>&1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
hostip=$(dig +nocmd +noall +answer A $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ')
|
||||||
|
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
|
||||||
|
if [ -n "$(nft list set inet fw4 omr_dst_bypass_all_4 2>/dev/null)" ]; then
|
||||||
|
for ip in $hostip; do
|
||||||
|
nft add element inet fw4 omr_dst_bypass_all_4 { $ip } >/dev/null 2>&1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bypass_host_disable() {
|
||||||
|
INTERFACE=$1
|
||||||
|
HOST=$2
|
||||||
|
domain=$(echo $HOST | awk -F/ '{print $3}')
|
||||||
|
if [ "$IPV6" = true ]; then
|
||||||
|
hostip=$(dig +nocmd +noall +answer AAAA $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ')
|
||||||
|
if [ -n "$(ipset list 2>/dev/null | grep ss_rules6)" ]; then
|
||||||
|
for ip in $hostip; do
|
||||||
|
ipset del ss_rules6_dst_bypass_all $ip
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ -n "$(nft list set inet fw4 omr_dst_bypass_all_6 2>/dev/null)" ]; then
|
||||||
|
for ip in $hostip; do
|
||||||
|
nft delete element inet fw4 omr_dst_bypass_all_6 { $ip } >/dev/null 2>&1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
hostip=$(dig +nocmd +noall +answer A $domain | grep -v CNAME | awk '{print $5}' | tr '\n' ' ')
|
||||||
|
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
|
||||||
|
if [ -n "$(nft list set inet fw4 omr_dst_bypass_all_4 2>/dev/null)" ]; then
|
||||||
|
for ip in $hostip; do
|
||||||
|
nft delete element inet fw4 omr_dst_bypass_all_4 { $ip } >/dev/null 2>&1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
/etc/init.d/sqm start $INTERFACE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
echo "Download server list..."
|
echo "Download server list..."
|
||||||
wget -q -O /tmp/speedtest.lst http://c.speedtest.net/speedtest-servers-static.php
|
wget -q -O /tmp/speedtest.lst https://www.speedtest.net/api/js/servers
|
||||||
bestuploadurl=""
|
bestuploadurl=""
|
||||||
besthost=""
|
besthost=""
|
||||||
bestpinghost=""
|
bestpinghost=""
|
||||||
bestping="999"
|
bestping="999"
|
||||||
echo "Select best server..."
|
echo "Select best server..."
|
||||||
while read line; do
|
while read line; do
|
||||||
if [ "$(echo $line | grep url)" != "" ]; then
|
host=$(echo $line | jsonfilter -e '@.host')
|
||||||
pinghost=$(echo $line | awk -F'"' '{print $18}' | cut -d: -f1)
|
pinghost=$(echo $host | awk -F: '{print $1}')
|
||||||
host=$(echo $line | awk -F'"' '{print $18}')
|
uploadurl=$(echo $line | jsonfilter -e '@.host')
|
||||||
uploadurl=$(echo $line | awk -F'"' '{print $2}')
|
ping=$(ping -c1 -w1 $pinghost | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
|
||||||
ping=$(ping -c1 -w1 $pinghost | cut -d "/" -s -f5 | cut -d "." -f1)
|
echo -n "."
|
||||||
echo -n "."
|
if [ -n "$ping" ] && [ "$ping" -lt "$bestping" ]; then
|
||||||
if [ -n "$ping" ] && [ "$ping" -lt "$bestping" ]; then
|
bestping=$ping
|
||||||
bestping=$ping
|
bestuploadurl=$uploadurl
|
||||||
bestuploadurl=$uploadurl
|
besthost=$host
|
||||||
besthost=$host
|
bestpinghost=$pinghost
|
||||||
bestpinghost=$pinghost
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done < /tmp/speedtest.lst
|
done < <(cat /tmp/speedtest.lst | jsonfilter -e '@[*]')
|
||||||
echo
|
echo
|
||||||
echo "Done: url: $bestuploadurl - host: $besthost - ping: $bestping"
|
echo "Done: url: $bestuploadurl - host: $besthost - ping: $bestping"
|
||||||
echo "Download test:"
|
echo "Download test:"
|
||||||
if [ -z "$INTERFACE" ]; then
|
if [ -z "$INTERFACE" ]; then
|
||||||
curl -4 $besthost/speedtest/random7000x7000.jpg >/dev/null || echo
|
curl -4 $besthost/speedtest/random7000x7000.jpg >/dev/null || echo
|
||||||
else
|
else
|
||||||
hostip=$(dig +short $bestpinghost | tr -d "\n")
|
bypass_host_enable $INTERFACE $bestpinghost
|
||||||
ipset add ss_rules_dst_bypass_all $hostip
|
|
||||||
curl -4 --interface $INTERFACE $besthost/speedtest/random7000x7000.jpg >/dev/null || echo
|
curl -4 --interface $INTERFACE $besthost/speedtest/random7000x7000.jpg >/dev/null || echo
|
||||||
ipset del ss_rules_dst_bypass_all $hostip
|
bypass_host_disable $INTERFACE $bestpinghost
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue