1

In past I've connected to VPN via Linux in Windows perfectly with python by using the following code:

    import win32ras

    hdl, retcode = win32ras.Dial (None, None, (vpn_name, ip, "", username, password, ""), None) #changing 'ip' will connect to that server ip

    win32ras.HangUp (hdl) #This disconnects the connection

So this works perfectly fine in windows with python but now I want to do it in ubuntu with python and I'm not sure how to do this at all. I want to do the same, define a VPN name and change its IP on connecting and input via username/password, if there's any other way, like directly connecting to the VPN without even making one then that's obviously better.

I'm finding the solution on internet as of now, will update if I find something.

Hoyo
  • 1,044
  • 3
  • 13
  • 23
  • You'll want to do it with D-Bus. If it was just a fixed connection you'd use http://unix.stackexchange.com/a/49321/45719, but you need some more calls on top of that to dynamically create the connection itself. (Similar to http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/gi/add_connection.py but not Ethernet obviously) – Flexo Jan 10 '15 at 10:54

1 Answers1

1

How about using the Linux PPTP Client: http://pptpclient.sourceforge.net/ ?

A few options for calling it from Python:

1) Call it as a command-line tool using subprocess: https://docs.python.org/2/library/subprocess.html

2) Build it as a library and call it via Cython: http://cython.org/

3) Build it as a Python package (and for bonus points, make it available to others!): https://docs.python.org/2/extending/extending.html

bsa
  • 2,671
  • 21
  • 31
  • This is a bad idea because it ignores the system for interface management in Ubuntu (NetworkManager). – Flexo Jan 10 '15 at 10:53
  • Good call. I don't know Ubuntu very well, so wasn't aware of NetworkManager. Maybe this package then: https://pypi.python.org/pypi/python-networkmanager – bsa Jan 10 '15 at 11:41