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.

# Author: Chrissy LeMaire
# Copyright 2003 NetNerds Consulting Group
# Script is provided AS IS with no warranties or guarantees and assumes no liabilities.
# Website:

    do shell script "date > /applescript/lastRan"
    do shell script "curl --connect-timeout 7 http://webserverOnVPN"
            on error
             do shell script "route flush"
                tell application "Internet Connect"
                set configName to "VPN"
                end tell
             do shell script "route add default [localGateway]"
                tell application "Internet Connect"
                set configName to "VPN"
                end tell
            delay 60
             do shell script "route flush"  -- just changing doesn't work nearly as well
             do shell script "route add default [localGateway]" -- so we flush and readd
             do shell script "route add -net [remoteSubnet] -netmask [localGatway]  -ifp ppp0"
             do shell script "echo "nameserver [localNameserver]" > /etc/resolv.conf"
             do shell script "date >> /applescript/dateLastBroken"

end 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.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, holds a master's degree in Systems Engineering and is coauthor of Learn dbatools in a Month of Lunches. Chrissy is certified in SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in Networking, Security

Leave a Reply