Skip to content

Instantly share code, notes, and snippets.

Last active December 24, 2021 07:25
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save collinbarrett/abeaf6edeb1cfb49d9beacd6d325d3c2 to your computer and use it in GitHub Desktop.
DD-WRT script for selecting an optimal ProtonVPN server
# specify PATH to run from cron
# kill openvpn
PID=$(pidof openvpn)
kill -s SIGTERM "$PID"
while $(kill -0 "$PID" 2>/dev/null); do
sleep 1
# fetch ProtonVPN server info
LOGICALS=$(curl -s -H "Cache-Control: no-cache" -H "Accept: application/json"
# 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" ]
sed -i '/^remote/d' /tmp/openvpncl/openvpn.conf
REMOTE="remote ${IP} 443"
echo $REMOTE >> /tmp/openvpncl/openvpn.conf
# restart openvpn
openvpn --config /tmp/openvpncl/openvpn.conf --route-up /tmp/openvpncl/ --route-pre-down /tmp/openvpncl/ --daemon
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment