1
votes

Need an applescript (which I haven't used before) to deploy our VPN connection settings on our remote workers mac boxes. this is for PPTP VPN.

Upon googling I came across the following link :
http://discussions.apple.com/thread.jspa?messageID=10368307

But still I can't :
a) seem to name the VPN connection
b) give it a pptp vpn server address
c) give dns, default gateway and any custom routes for this vpn to work
.

How can I add those fields / enteries in ?

tell application “System Preferences”
reveal pane “Network”
activate
tell application “System Events”
tell process “System Preferences”
tell window 1
click button “Add Service”
tell sheet 1
click pop up button 1
click menu item “VPN” of menu 1 of pop up button 1
delay 1
click pop up button 2
click menu item “PPTP” of menu 1 of pop up button 2
click button “Create”
end tell
click button “Apply”
end tell
end tell
delay 1 — optional (just for visual feedback)
keystroke “w” using {command down}
end tell
end tell

The above script seems to create the connection just fine but without the details - and I am not sure about what syntax I would use to get this going.

Thanks for your input!
Regards
Thanks

3

3 Answers

2
votes

Rihatum, here's the full Applescript with all the things you want to do.

--create new VPN PPTP service on the ethernet interface
do shell script "networksetup -createnetworkservice \"VPN (PPTP)\" en0 - where en0" with administrator privileges

--set the IP, subnet, & router IP ( order = ip subnet route )
do shell script "networksetup -setmanual \"VPN (PPTP)\" 192.168.2.50 255.255.255.0 192.168.2.1" with administrator privileges

--set VPN service using DHCP  -- if using DHCP don't use manual setting above
do shell script "networksetup -setdhcp \"VPN (PPTP)\"" with administrator privileges

--set DNS
do shell script "networksetup -setdnsservers \"VPN (PPTP)\" 208.67.222.222" with administrator privileges  

--set search domain 
do shell script "networksetup -setsearchdomains \"VPN (PPTP)\" my_company_domain.com" with administrator privileges

--rename network service -- replace CISCO_VPN with your preferred name
do shell script "networksetup -renamenetworkservice \"VPN (PPTP)\" CISCO_VPN" with administrator privileges
2
votes

I tried the solution using the networksetup tool, but it didn't work for me :S I actually came up with a successful script using UI automation. It put up a post about it here: http://blog.affirmix.com/2011/01/12/how-to-configure-a-vpn-in-mac-os-x-usingapplescript/

1
votes

I think what you want to do is build a script using the networksetup command and use a series of "do shell script" lines in your AppleScript instead of trying to GUI script the configuration.

Fo example, in your AppleScript this command will create a new VPN PPTP connection on the ethernet interface:

do shell script "networksetup -createnetworkservice \"VPN (PPTP)\" en0 -where en0" with administrator privileges

To set the IP, subnet, & router IPs you would use this: ( -setmanual networkservice ip subnet router )

do shell script "networksetup -setmanual \"VPN (PPTP)\" 192.168.2.50 255.255.255.0 192.168.2.1" with administrator privileges

After that you can use the other options to configure the rest. For example, to add a DNS IP to your newly created VPN PPTP connection you would add this to your AppleScript:

do shell script "networksetup -setdnsservers \"VPN (PPTP)\" 208.67.222.222" with administrator privileges

Check out the man page for the networksetup command. It does a tremendous amount of things. Also, you can Google that command and you will find a lot of forums with people discussing Mac command line network configurations. The single keyword networksetup doesn't work too well because it returns a lot of Windows pages so Google for "sudo networksetup" and that will return Mac related pages.