Only torrent when VPN is active (Page 1) / General (Mac) / µTorrent Community Forums
 

#1 2010-04-15 21:36:29

Dijhammond
Member

Only torrent when VPN is active

I have been looking for a solution for this but have not been able to find one as of yet.

I connect to a VPN and then my torrent client starts. However, since i am using a campus network, my VPN frequently disconnects and earn torrent is running when my VPN isn't, it kind of defeats the purpose. I was wondering if there was a way to prevent torrent from connecting when my VPN is down or force all traffic through the VPN so that when it goes down, utorrent thinks its been disconnected form the internet. .

Btw, all of this is done on a Mac mini used as a HTPC so I am not constantly monitoring the status foe the VPN connection and as a result I need an "automated" solution.

  Any help would be greatly appreciated. Thanks.

Offline

#2 2010-04-16 05:04:25

mains.voltage
Member

Re: Only torrent when VPN is active

I use an applescript to check the vpn, and activate it if it goes down

on idle
    tell application "System Events"
        tell current location of network preferences
            set myConnection to the service "VPN"
            if current configuration of myConnection is not connected then
                connect myConnection
            end if
        end tell
        return 120
    end tell
end idle

Save it as an application with the check box stay open, and then set it to start at login.

VPN is the name of you vpn, and the 120 checks every 2 minutes.

Last edited by mains.voltage (2010-04-16 08:47:50)

Offline

#3 2010-07-17 13:20:07

StevenMichaelSmith86
Member

Re: Only torrent when VPN is active

a

Offline

#4 2011-08-06 11:21:35

sprocketeer
Member

Re: Only torrent when VPN is active

I've posted a solution on my blog using Vuze (formerly Azureus) which is a terrible piece of bloatware, but highly configurable:

http://continentalroast.blogspot.com/20 … -your.html

If you find a better way that does not require a script, let me know.

Offline

#5 2012-04-16 19:42:30

Jack0817
Member

Re: Only torrent when VPN is active

Here is a script I've created that will get the job done until uTorrent (for Mac) can bind to a VPN service.  SImply update the "Scrip Variables" section with your corresponding values, save the script AS AN APP, and add it to your Login Startup Items.

The Gist: This script will monitor your VPN connection, if it detects it is no longer connected it will gracefully shutdown uTorrent (keeping all DL progress intact).  Also, when the VPN is down, it will continue to try to re-establish a connection and upon successful re-connecting, it will then re-launch uTorrent to resume where it left off.

Hope this helps!

------------------------------------------------
--Main Routine
------------------------------------------------
on idle
   
    --Script Variables
    set appName to "uTorrent"
    set vpnName to "IPredator"
    set waitTIme to 60 as integer
   
    --Main Script Logic
    if isVPNConnected(vpnName) then
        startApplication(appName)
    else
        stopApplication(appName)
        connectVPNConnection(vpnName)
    end if
   
    return waitTIme
   
end idle

------------------------------------------------
--Sub Routine - Determines if specified vpn is connected
------------------------------------------------
on isVPNConnected(vpnName)
   
    --Init return value to default
    set isConnected to false
   
    tell application "System Events"
        tell current location of network preferences
            set vpnConnection to the service vpnName
            set isConnected to current configuration of vpnConnection is connected
        end tell
    end tell
   
    return isConnected
   
end isVPNConnected

------------------------------------------------
--Sub Routine - Attempts to connect to the specified VPN
------------------------------------------------
on connectVPNConnection(vpnName)
   
    tell application "System Events"
        tell current location of network preferences
            set vpnConnection to the service vpnName
            if vpnConnection is not null then
                connect vpnConnection
            end if
        end tell
    end tell
   
end connectVPNConnection

------------------------------------------------
--Sub Routine - Starts an application if it is not already running
------------------------------------------------
on startApplication(appName)
   
    if appIsRunning(appName) is false then
        tell application appName to activate
    end if
   
end startApplication

------------------------------------------------
--Sub Routine - Stop an application if it is running
------------------------------------------------
on stopApplication(appName)
   
    if appIsRunning(appName) then
        tell application appName to quit
    end if
   
end stopApplication

------------------------------------------------
--Sub Routine - Determines if specified app is currently running
------------------------------------------------
on appIsRunning(appName)
   
    set isRunning to false
   
    tell application "System Events"
        set isRunning to (name of processes) contains appName
    end tell
   
    return isRunning
   
end appIsRunning

Last edited by Jack0817 (2012-04-16 19:44:36)

Offline

#6 2012-05-06 06:35:06

g3nius
Member

Re: Only torrent when VPN is active

g3nius wrote:

Hey so like the topic says I am working on a script that will stop all the transfers when my VPN goes down.  Currently the program is set to quit (but this takes a while)  This is not my code and was changed from https://forum.transmissionbt.com/viewto … vpn#p56986

on idle
	set activeInterfaces to do shell script "ifconfig -lu"
	if activeInterfaces = "lo0 en0 en1 fw0 utun0" then
		tell application "uTorrent" to quit
		tell application "Growl"
			notify with name ¬
				"VPN Down" title ¬
				"VPN Down" description ¬
				"I have quit uTorrent." application name "Drop BitTorrent"
		end tell
	end if
	return 5 -- 30 is default value, but it doesn't hurt to include it here
end idle

Does any one know what command I could substitute for the line: ??

tell application "uTorrent" to quit

stop doesn't seem to work and I can't really guess.  I also can't seem to find a key command to start/stop transfers


Also what would I add to reenable the transfers?
something like:

if activeInterfaces = "lo0 en0 en1 fw0 utun0 tun0"
tell application "uTorrent" to start (or something to that effect)
if activeInterfaces = "lo0 en0 en1 fw0 tun0 utun0"
tell application "uTorrent" to start (or something to that effect)

Offline

#7 2012-05-25 09:54:41

cl0r
Member

Re: Only torrent when VPN is active

any good ways of testing whether the scripts are working?
before relying on them completely, that is.

Offline

#8 2012-05-25 13:21:50

g3nius
Member

Re: Only torrent when VPN is active

cl0r wrote:

any good ways of testing whether the scripts are working?
before relying on them completely, that is.

sure, pause torrents.  disconnect vpn... see if the program quits.  rinse repeat until satisfied

Offline

#9 2012-06-10 20:28:38

g3nius
Member

Re: Only torrent when VPN is active

this what I settled on, seems to work better and will not drop with a simple reordering of interface types

on idle
	set activeInterfaces to do shell script "ifconfig -lu"
	if activeInterfaces is "lo0 en0 en1 fw0 tun0 utun0" then
		return
	else if activeInterfaces is "lo0 en0 en1 fw0 utun0 tun0" then
		return
	else
		tell application "uTorrent" to quit
		tell application "Growl"
			notify with name ¬
				"VPN Down" title ¬
				"VPN Down" description ¬
				"I have quit uTorrent." application name "Drop BitTorrent"
		end tell
	end if
	return 5 -- 30 is default value, but it doesn't hurt to include it here
end idle

Offline

#10 2012-08-26 13:27:05

g3nius
Member

Re: Only torrent when VPN is active

I recently upgraded my computer and because the interfaces list is different I modified the code above to this.  Should produce more consistency.

on idle
	
	set activeInterfaces to do shell script "ifconfig -lu"
	set activeInterfacesString to (activeInterfaces) as string
	
	set AppleScript's text item delimiters to " "
	set the activeInterfacesList to every text item of the activeInterfacesString
	set AppleScript's text item delimiters to ""
	if activeInterfacesList does not contain "tun0" then
		tell application "uTorrent" to quit
		tell application "Growl"
			notify with name ¬
				"VPN Down" title ¬
				"VPN Down" description ¬
				"I have quit uTorrent." application name "Drop BitTorrent"
		end tell
	end if
	return 5 -- 30 is default value, but it doesn't hurt to include it here
end idle

Offline

#11 2012-10-16 12:22:14

Alex-007-
Member

Re: Only torrent when VPN is active

The answers are: VPN Lifeguard, VPNetMon, VPNCheck and others.
Some good night reading on this subject here:
http://torrentfreak.com/how-to-make-vpn … re-120419/
Enjoy.. ;-)

Offline

#12 2012-10-16 14:55:13

g3nius
Member

Re: Only torrent when VPN is active

Alex-007- wrote:

The answers are: VPN Lifeguard, VPNetMon, VPNCheck and others.
Some good night reading on this subject here:
http://torrentfreak.com/how-to-make-vpn … re-120419/
Enjoy.. ;-)

good solutions.... For windows users.  Seeing that we are in the general (Mac) forum however these are not viable solutions...

Offline

#13 2013-02-18 08:29:18

JunkBox
Member

Re: Only torrent when VPN is active

Before: I left my computer downloading movies via uTorrent, and came home to find my vpn disconnected, uTorrent still running, and my IP being sprayed all over the place.
After: The script first connects my vpn of choice and opens uTorrent. Then it repeats the following indefinitely: watches the Tunnelblick connection every 1 second. If it is connected, it just keeps checking every second until it detects a disconnect. Upon disconnect, it quits uTorrent, reconnects the vpn connection via tunnelblick, and restarts uTorrent. Please find the applescript below:

tell application "Tunnelblick"
    connect "config"
    get state of first configuration where name = "config"
    repeat until result = "CONNECTED"
        delay 1
        get state of first configuration where name = "config"
    end repeat
    if result = "connected" then run application "uTorrent"
end tell
repeat
    tell application "Tunnelblick"
        get state of configuration 1 whose name = "config"
        if result = "connected" then repeat until result = "exiting"
            delay 1
            get state of configuration 1 whose name = "config"
        end repeat
        if result = "exiting" then quit application "uTorrent"
        tell application "Tunnelblick"
            connect "config"
            get state of first configuration where name = "config"
            repeat until result = "CONNECTED"
                delay 1
                get state of first configuration where name = "config"
            end repeat
            run application "uTorrent"
        end tell
    end tell
end repeat

"config" is replaced with my vpn of choice as it appears in the tunnelblick drop down menu. I was so excited that it worked, I had to share it.

You should be able to copy the script into applescript editor and just replace that which does not apply to your set up with the relevant info.

Offline

#14 2013-03-13 21:35:32

steiney
Member

Re: Only torrent when VPN is active

JunkBox,

I just started using a VPN, and although I'm pretty proficient with OS X, AppleScript is a skill that I lack. Would you be so kind as to tell me which parts of that code need to be switched out, as you mentioned?

I'm using tunnelblick and uTorrent on 10.6.8. I can't see anything else in the code that stands out as something that would need to be changed.

Thanks in advance for helping out a noob!

steiney

Offline

#15 2013-04-01 14:21:03

lukekjones
Member

Re: Only torrent when VPN is active

Sorry to bump an old post to the top but another answer to only torrenting while your vpn is active is detailed here:

http://superuser.com/questions/468919/p … conf-on-ma

I have set it up and tested it with positive results.

Last edited by lukekjones (2013-04-01 14:33:06)

Offline

#16 2013-04-11 05:20:44

alastairandrew
Member

Re: Only torrent when VPN is active

Dijhammond wrote:

I have been looking for a solution for this but have not been able to find one as of yet.

I connect to a VPN and then my torrent client starts. However, since i am using a campus network, my VPN frequently disconnects and earn torrent is running when my VPN isn't, it kind of defeats the purpose. I was wondering if there was a way to prevent torrent from connecting when my VPN is down or force all traffic through the VPN so that when it goes down, utorrent thinks its been disconnected form the internet. .

Btw, all of this is done on a Mac mini used as a HTPC so I am not constantly monitoring the status foe the VPN connection and as a result I need an "automated" solution.

  Any help would be greatly appreciated. Thanks.

I have tried a few VPN provider before and i would say Torguard VPN is the most stable to use since they have quite a number of server location worldwide.But the package is quite pricey compared to other VPN provider.

Here is the list of Best P2P and top Torrent VPN Service Providers that help you to download via torrent and share p2p files anonymously. Now you can Access to any Internet resource without restrictions and bandwidth limitation safe, secure and fast with Torrent VPN accounts.

Offline

Board footer

Powered by FluxBB

©2013 BitTorrent, Inc. µTorrent is a trademark of BitTorrent, Inc.