jotyGill / openpyn-nordvpn

Easily connect to and switch between, OpenVPN servers hosted by NordVPN on Linux (+patch leakes)
GNU General Public License v3.0
628 stars 114 forks source link

python API #232

Closed dizcza closed 5 years ago

dizcza commented 5 years ago

I want to use openpyn directly in python code. If it's already written in python, could you please provide API for doing this? Basically, my scenario is the following:

  1. start openpyn and remember its session to be closed later on
  2. do some stuff in python
  3. close openpyn connection (without the root access)

I think I can do this with subprocess though maybe there is direct way to import openpyn and call it.

chazanov commented 5 years ago

@dizcza Just file a pull request, I guess.

dizcza commented 5 years ago

Nordvpn team (I guess, not sure) made linux package that you can install with

sudo apt install nordpvn

Then wrap your python function with the decorator:

def nordvpn(func):
    def under_vpn(*args, **kwargs):
        subprocess.call('nordvpn connect'.split())
        res = func(*args, **kwargs)
        subprocess.call('nordvpn disconnect'.split())
        return res
    return under_vpn

Usage:

@nordvpn
def your_function_that_you_want_to_run_under_vpn():
    pass

I've been using it for months and it works flawlessly and does not require sudo at runtime.

If your_function_that_you_want_to_run_under_vpn might exit with non-zero error code, you can always register a callback that closes opened nordvpn connection with atexit even if an error is occured.

s3afroze commented 4 years ago

sudo apt install nordvpn