Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
""" TapDat - Simple VPN Setup.
import re
import sys
from commands import getoutput as cmd
def main():
"""Sets split-tunnled VPN access for NetApp"""
print 'TapDat: Simple VPN Setup'
print 'Picking up stones...'
old_gateway = get_gateway()
print 'Opening the floodgates...'
print 'Dat has been Tapt'
def get_gateway():
"""Returns existing default gateway"""
existing_route = cmd("route get default | grep 'gateway'")
reg = r'.*?((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\d])'
rg = re.compile(reg, re.IGNORECASE|re.DOTALL)
m =
def set_gateway(gate):
"""Sets system default to given gateway"""
print cmd("sudo route change default {0}".format(gate))
def open_vpn():
"""Opens VPN connection and adds appropriate routes"""
vpn_script = '''
tell application "System Events"
tell current location of network preferences
set VPNservice to service "NetApp" -- name of the VPN service
if exists VPNservice then connect VPNservice
end tell
end tell
cmd("echo '{0}' | osascript".format(vpn_script))
raw_input('Enter when ready.')
cmd("sudo route -nv add -net 10 -interface utun0")
if __name__ == '__main__':

This comment has been minimized.

Copy link

@kennethreitz42 kennethreitz42 commented Jun 15, 2010

I was hoping you'd improve upon it :P


This comment has been minimized.

Copy link
Owner Author

@bobthecow bobthecow commented Jun 16, 2010

Oh, I don't actually need this implementation. I just filed it away as "maybe I'll base a VPN management script on this later" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment