Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DD-WRT script for selecting an optimal ProtonVPN server
#!/bin/sh
# https://collinmbarrett.com/protonvpn-dd-wrt-api-script/
# specify PATH to run from cron
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin
# kill openvpn
PID=$(pidof openvpn)
kill -s SIGTERM "$PID"
while $(kill -0 "$PID" 2>/dev/null); do
sleep 1
done
# fetch ProtonVPN server info
LOGICALS=$(curl -s -H "Cache-Control: no-cache" -H "Accept: application/json" https://api.protonmail.ch/vpn/logicals)
# query for optimal server
IPSTRING=$(echo "$LOGICALS" | jq '.LogicalServers | map(select(.Status == 1 and .Tier == 2 and (.Name | (startswith("US-TX#") or startswith("US-GA#")) and (endswith("TOR") | not)))) | [sort_by(.Score, .Load)[]][0] | .Servers[0].EntryIP')
# update openvpn config
if [ -n "$IPSTRING" ]
then
sed -i '/^remote/d' /tmp/openvpncl/openvpn.conf
IPSTRING="${IPSTRING%\"}"
IP="${IPSTRING#\"}"
REMOTE="remote ${IP} 443"
echo $REMOTE >> /tmp/openvpncl/openvpn.conf
fi
# restart openvpn
openvpn --config /tmp/openvpncl/openvpn.conf --route-up /tmp/openvpncl/route-up.sh --route-pre-down /tmp/openvpncl/route-down.sh --daemon
@collinbarrett

This comment has been minimized.

Copy link
Owner Author

@collinbarrett collinbarrett commented Jun 6, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.