Mac OS X 10.5.1

Below is how to establish a PPTP VPN session from the command line in OS X. Note you must first set up the VPN connection in System Preferences->Network. I use this to connect to a Cisco 827H router running IOS. If there is any interest, I'll post instructions on how to setup an IOS router for PPTP or IPSEC VPN connections (your choice, but the IPSEC requires the Cisco VPN Client for Mac).

I'm saving everything to ~/bin in the example below. Make modifications as you see fit.

  1. Open Script Editor and paste the following script in:

    tell application "System Events"
    tell current location of network preferences
    set VPNservice to service "VPN (PPTP)"
    if exists VPNservice then connect VPNservice
    end tell
    end tell

  2. Save as ~/bin/pptp_connect.scpt


  3. In Script Editor, File->New, then paste the following script in:

    tell application "System Events"
    tell current location of network preferences
    set VPNservice to service "VPN (PPTP)"
    set isConnected to connected of current configuration of VPNservice
    if isConnected then disconnect VPNservice
    end tell
    end tell

  4. Save as ~/bin/pptp_disconnect.scpt


  5. Open your favorite text editor, such as vi, and paste the following shell script:

    #!/bin/sh -
    osascript pptp_connect.scpt

  6. Save as ~/bin/pptp_connect.sh


  7. Paste the following shell script in a new text editor window:

    #!/bin/sh -
    osascript pptp_disconnect.scpt

  8. Save as ~/bin/pptp_disconnect.sh


  9. Execute the following command to make the scripts executable by everyone:

    chmod +x ~/bin/pptp_*.sh


    Now in your terminal, you can execute ~/bin/pptp_connect.sh or ~/bin/pptp_disconnect.sh to establish or tear down your PPTP connection.

    This works with L2TP VPN connections also. Where you see "VPN (PPTP)" simply change it to "VPN (L2TP)".