Skip to content

Instantly share code, notes, and snippets.

@ebroder
Created January 10, 2014 23:05
Show Gist options
  • Save ebroder/8364402 to your computer and use it in GitHub Desktop.
Save ebroder/8364402 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import subprocess
from gi.repository import GLib, NMClient
def active_connections_changed(*args):
for sock in os.listdir(os.path.expanduser('~/.ssh/sockets')):
user, hostport = sock.split('@')
host, port = hostport.split(':')
subprocess.call(['ssh', '-O', 'stop', '-l', user, '-p', port, host])
c = NMClient.Client.new()
c.connect('notify::active-connections', active_connections_changed)
GLib.MainLoop().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment