AppleScript: McVPN

This bandaid is mighty handy for pesky OSX disconnects. I don't really know what causes it and unfortunately, I don't have time to fully figure it out. I do know that changing my gateway back to my local gateway helped tremendously. Also, changing my default nameserver to a local nameserver helped too. Now, I get disconnected but its after hours or days instead of minutes.

My system.log referred to lookupd issues and my ping had some sort of buffer problem. That's for you Googlers looking for a solution. Well, here's one...sorta. Throw this in a cron job run by root.

 1# Author: Chrissy LeMaire
 2# Copyright 2003 NetNerds Consulting Group
 3# Script is provided AS IS with no warranties or guarantees and assumes no liabilities.
 4# Website: https://www.netnerds.net
 5
 6try
 7    do shell script "date > /applescript/lastRan"
 8    do shell script "curl --connect-timeout 7 https://webserverOnVPN"
 9            on error
10             do shell script "route flush"
11                tell application "Internet Connect"
12                set configName to "VPN"
13                Disconnect
14                end tell
15             do shell script "route add default [localGateway]"
16                tell application "Internet Connect"
17                set configName to "VPN"
18                Connect
19                end tell
20            delay 60
21             do shell script "route flush"  -- just changing doesn't work nearly as well
22             do shell script "route add default [localGateway]" -- so we flush and readd
23             do shell script "route add -net [remoteSubnet] -netmask 255.255.255.0 [localGatway]  -ifp ppp0"
24             do shell script "echo "nameserver [localNameserver]" > /etc/resolv.conf"
25             do shell script "date >> /applescript/dateLastBroken"
26
27end try

This script requires that you have a webserver on the VPN..that's how it checks for a connection. Internet Connect will sometimes report that it's connected when it's not working so this is a better way to tell. It then issues a few commands to change the gateway back to the local one and then rewrites the resolv.conf so that DNS lookups are performed on a local dns server instead of over the VPN.

If I ever have the time figure out how to fix this intead of applying a band-aid, I'll be sure to update this page.