Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@OpenWrt:~# cat /etc/config/network | grep endpoint_host
- option endpoint_host 'sg494.nordvpn.com'
- @@@@@@@@@@@@@@@@@@@@@@
- root@OpenWrt:~# ping -I nordlynx google.com
- PING google.com (172.217.31.14): 56 data bytes
- 64 bytes from 172.217.31.14: seq=0 ttl=114 time=74.798 ms
- 64 bytes from 172.217.31.14: seq=1 ttl=114 time=74.787 ms
- 64 bytes from 172.217.31.14: seq=2 ttl=114 time=74.573 ms
- ^C
- --- google.com ping statistics ---
- 3 packets transmitted, 3 packets received, 0% packet loss
- round-trip min/avg/max = 74.573/74.719/74.798 ms
- @@@@@@@@@@@@@@@@@@@@@@
- root@OpenWrt:~# ping -I br-lan google.com
- PING google.com (172.217.31.14): 56 data bytes
- 64 bytes from 172.217.31.14: seq=0 ttl=117 time=27.894 ms
- 64 bytes from 172.217.31.14: seq=1 ttl=117 time=27.514 ms
- 64 bytes from 172.217.31.14: seq=2 ttl=117 time=27.737 ms
- ^C
- --- google.com ping statistics ---
- 3 packets transmitted, 3 packets received, 0% packet loss
- round-trip min/avg/max = 27.514/27.715/27.894 ms
- @@@@@@@@@@@@@@@@@@@@@@
- root@OpenWrt:~# cat ./pingv4.sh
- #!/bin/sh
- check_ping () {
- server="$1"
- interface="$2"
- count=0
- while [ "$count" -lt 5 ]; do
- ping_output=$(ping "$server" -c 1 -I "$interface" -W 5)
- ping_time=$(printf "%.0f" "$(echo "$ping_output" | grep 'time=' | awk -F 'time=' '{print $2}' | awk '{print $1}')")
- if [ -n "$ping_time" ] && [ "$ping_time" -gt 0 ]; then
- break
- fi
- count=$((count+1))
- sleep 1
- done
- }
- find_fastest_server () {
- server_list="/etc/servers"
- fastest_ping=100
- fastest_server=
- interface="br-lan"
- while IFS= read -r server; do
- echo "Checking server: $server"
- check_ping "$server" "$interface" &>/dev/null
- if [ "$ping_time" -lt "$fastest_ping" ]; then
- fastest_server="$server"
- fastest_ping="$ping_time"
- fi
- done < "$server_list"
- }
- ifname="nordlynx"
- echo "Pinging..."
- check_ping "8.8.8.8" "$ifname" &>/dev/null
- echo "Current ping: $ping_time"
- # Check if VPN ping is lower than 50ms
- if [ "$ping_time" -eq 0 ] || [ "$ping_time" -lt 10 ]; then
- exit 0
- else
- find_fastest_server
- echo "Fastest server: $fastest_server"
- echo "Fastest ping: $fastest_ping ms"
- # If there is no error left, remove this line and all # at the beginning of the 3 following lines
- #uci set network.@wireguard_${ifname}[-1].endpoint_host="$fastest_server"
- #uci commit network
- #/etc/init.d/network restart
- fi
- exit 0
- @@@@@@@@@@@@@@@@@@@@@@
- root@OpenWrt:~# ./pingv4.sh
- Pinging...
- Current ping: 39
- Checking server: sg491.nordvpn.com
- Checking server: sg493.nordvpn.com
- Checking server: sg494.nordvpn.com
- Checking server: sg455.nordvpn.com
- Checking server: sg508.nordvpn.com
- Checking server: sg456.nordvpn.com
- Checking server: sg507.nordvpn.com
- Checking server: sg490.nordvpn.com
- Checking server: sg459.nordvpn.com
- Checking server: sg460.nordvpn.com
- Checking server: sg457.nordvpn.com
- Checking server: sg461.nordvpn.com
- Checking server: sg462.nordvpn.com
- Checking server: sg463.nordvpn.com
- Checking server: sg458.nordvpn.com
- Fastest server: sg491.nordvpn.com
- Fastest ping: 29 ms
- @@@@@@@@@@@@@@@@@@@@@@
- root@OpenWrt:~# cat /etc/config/network | grep endpoint_host
- option endpoint_host 'sg494.nordvpn.com'
- root@OpenWrt:~#
Advertisement
Add Comment
Please, Sign In to add comment