DD-WRT: Script for IP checking and openVPN reconnect

خرید بک لینک

Router: TPLINK ARCHER-C7 v2

Firmware: DD-WRT v3.0-r28072 std (11/02/15)

Service: OpenVPN client

Issue: Sometimes a least favorable VPN server is assigned, it always provides very slow connection speeds.

Solution approach: Check the current IP and reconnect if needed. In case the assigned server is the same try again.

Progress so far: I managed to collect some ideas from here and there. The following script does not seem to work. I am not even sure that the conditional loop is written right... Also I do not know if this should be a startup script, a firewall script or something else. The concept is: If my current ip address contains e.g the number 188 then stop openvpn service, restart dns service and reconnect to VPN service.

if wget -qO- ipinfo.io/ip | grep -c 188; then
    # kill active openvpn client
    if killall -q openvpn; then
        # restart dns server (if running)
        if pidof dnsmasq > /dev/null 2>&1; then
            sleep 2; stopservice  dnsmasq
            sleep 2; startservice dnsmasq
        fi
        sleep 10
    fi
fi
openvpn --config /tmp/openvpncl/openvpn.conf 
    --route-up /tmp/openvpncl/route-up.sh 
--route-pre-down /tmp/openvpncl/route-up.sh --daemon

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 174 تاريخ: شنبه 8 خرداد 1395 ساعت: 7:15

صفحه بندی