run script on creating VPN instance

30 views
Skip to first unread message

Roy Nielsen

unread,
Mar 30, 2010, 4:35:47 PM3/30/10
to PyMacAdmin
Hello,

Do you think it would be possible to run a script when a VPN in
instance is started?

Regards,
-Roy

Nigel Kersten

unread,
Mar 30, 2010, 5:22:25 PM3/30/10
to pymac...@googlegroups.com
On Tue, Mar 30, 2010 at 1:35 PM, Roy Nielsen <amr...@gmail.com> wrote:
> Hello,
>
> Do you think it would be possible to run a script when a VPN in
> instance is started?

Yes. You could watch for the network interface coming up, or you could
watch for any IP changes and check if the relevant interface is there.

>
> Regards,
> -Roy
>
> --
> You received this message because you are subscribed to the Google Groups "PyMacAdmin" group.
> To post to this group, send email to pymac...@googlegroups.com.
> To unsubscribe from this group, send email to pymacadmin+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pymacadmin?hl=en.
>
>

Roy Nielsen

unread,
Mar 30, 2010, 6:41:43 PM3/30/10
to pymac...@googlegroups.com
Sounds good -- so I could have a config file something like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>SystemConfiguration</key>
      <dict>

        <key>Plugin:IPConfiguration</key>
        <dict>
          <key>command</key>
          <string>myscript.sh 'SystemConfiguration' 'Plugin:IPConfiguration'</string>
        </dict>
  </dict>
</dict>
</plist>

and run crankd like:

/path/to/bin/crankd.py --config=mycrankd-config.plist

-- is the above plist what I would be looking for in a "change of IP"?

Thanks,
-Roy

Nigel Kersten

unread,
Mar 30, 2010, 7:18:08 PM3/30/10
to pymac...@googlegroups.com
I tend to write modules rather than scripts.

<key>SystemConfiguration</key>
<dict>
<key>State:/Network/Global/IPv4</key>
<dict>
<key>method</key>
<array>
<string>NetworkStateChange</string>
<string>OnNetworkStateChange</string>
</array>
</dict>
</dict>


and then have:
/Library/Application Support/crankd/NetworkStateChange.py

that includes:

class NetworkStateChange(object):
"""class to be triggered on network state changes."""
.....
def OnNetworkStateChange(self, *unused_args, **unused_kwargs):
"""entry point for network state changes, triggered by crankd."""
.....


We found here that we were sharing lots of utility methods between
various crankd objects, so we have a common set of python libraries
that get included by our crankd modules.

Greg Neagle

unread,
Mar 30, 2010, 7:23:00 PM3/30/10
to pymac...@googlegroups.com
Gosh I keep wishing you'd write up something on your implementation...

-Greg

Clay Caviness

unread,
Mar 30, 2010, 7:23:52 PM3/30/10
to pymac...@googlegroups.com
We can barely understand it ourselves, much less document it.

To unsubscribe from this group, send email to pymacadmin+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/pymacadmin?hl=en.

Roy Nielsen

unread,
Mar 30, 2010, 7:26:01 PM3/30/10
to pymac...@googlegroups.com
Cool.

Been meaning to learn python for a while.  Looks like I've got my chance now :)

Regards,
-Roy

Nigel Kersten

unread,
Mar 30, 2010, 7:26:10 PM3/30/10
to pymac...@googlegroups.com
On Tue, Mar 30, 2010 at 4:23 PM, Greg Neagle <gregn...@mac.com> wrote:
> Gosh I keep wishing you'd write up something on your implementation...

I keep wishing that too :(

My contributions to all these things have gone rapidly down hill since
I came to a new arrangement with my family about computer usage when
at home :)

Greg Neagle

unread,
Mar 30, 2010, 7:27:28 PM3/30/10
to pymac...@googlegroups.com
I've come to no such arrangement. And it will only get worse come
April 3.

-Greg

Nigel Kersten

unread,
Mar 30, 2010, 8:06:24 PM3/30/10
to pymac...@googlegroups.com
On Tue, Mar 30, 2010 at 4:26 PM, Roy Nielsen <amr...@gmail.com> wrote:
> Cool.
>
> Been meaning to learn python for a while.  Looks like I've got my chance now
> :)

http://www.diveintopython.org :)

Roy Nielsen

unread,
Mar 31, 2010, 10:31:31 AM3/31/10
to pymac...@googlegroups.com
Cool Thanks!
-Roy

Jeremy Reichman

unread,
Apr 1, 2010, 2:44:36 PM4/1/10
to pymac...@googlegroups.com
> I keep wishing that too :(
>
> My contributions to all these things have gone rapidly down hill since
> I came to a new arrangement with my family about computer usage when
> at home :)

My family's coming to a new arrangement with me in a few months.

On-topic, another way you might approach running a script when a VPN
connection is active is to use the facilities of the VPN client itself.

If you have the Cisco AnyConnect client, for example, OnConnect and
DisConnect scripts are an option; they trigger at the connect and disconnect
events, as you'd expect. I can't speak from experience using them, yet, but
they're documented in the client admin guide. Apparently they can be in any
language the client OS understands, and can be downloaded from a Cisco ASA
during its profile policy refresh. Although you can only run one script at
each event, the single script can call others, so it ought to be familiar to
those of us used to Login/LogoutHooks.


--
Jeremy


Roy Nielsen

unread,
Apr 1, 2010, 3:04:04 PM4/1/10
to pymac...@googlegroups.com
My company abandoned cisco and is now using juniper...

I'll have to see if something like that is available with juniper.

I'm still testing with pymacadmin - I like to keep my options open :)

Regards,
-Roy




--
Reply all
Reply to author
Forward
0 new messages