Page 1 of 1

Auto connect to VPN, d/l, then disc

Posted: 10 Jun 2015, 22:19
by iamnotmad
Hello all, is there an easy way I can do this? I want NZBGet to connect to a VPN when it gets an NZB before downloading, then disconnect when the queue is empty. I'm on OS X.
Any thoughts?

Re: Auto connect to VPN, d/l, then disc

Posted: 11 Jun 2015, 10:58
by cytec
Depends on which Version of OS X you are. i think starting with Lion there is a command called scutil. If you are useing a "default" VPN Supportet by OS X (PPTP, L2TP, IPSec) you can just enter all you informations in Network Settings and create a new VPN which then can be controlled via `scutil` ill give you a little example here:

Code: Select all

scutil --nc start NameOfVPN
scutil --nc stop  NameOfVPN
scutil --nc status NameOfVPN
then you'll make 2 scripts:

1. Running when NZB is added: checking for connection if not connected goe through connection loop till it is connected
2. Running after downloads finished: checking if there are still downloads left, if not: disconnect

If you don't use apples default/supportet VPN's or use an external App etc. you may have to use applescript

EDIT: I've attached a little script that when called will connect if no connection is given and disconnect if it is connected

Code: Select all


set -e
#set -x


check_connecttion () {
    status=`scutil --nc status ${vpn} | sed -n 1p`
    if [ $status = "Connected" ]; then
        return 1

start_connection() {
    scutil --nc start "${vpn}"

close_connection() {
    scutil --nc stop "${vpn}"

wait_for_status ()
    while [ ${counter} -gt 0 ]; do
        [ $? -eq $1 ] && return
        let counter=counter-1
        sleep 1
    return 1

if check_connecttion; then
    echo "im connected, disconnecting now!"
    wait_for_status 1 10 || close_connection
    echo "not connected, connecting now!"
    wait_for_status 0 10 || start_connection

Re: Auto connect to VPN, d/l, then disc

Posted: 12 Jun 2015, 12:54
by iamnotmad
Sweet. I will try this. I do plan to use the built-in VPN client. Thanks a lot for the help, I'll let you know how it goes!