Hello everybody here is a solution I found and modified. I am using it on Debian however, I don't see why it wouldn't work on Ubuntu. I suspect that most recent versions of Ubuntu are running python 3 so you may have to use input() instead of raw_input().
I found it at http://forums.fedoraforum.org/showthread.php?t=228773 and made some modifications.
When the VPN connection is lost or manually disconnected it will disable the network adapter. Just change "eth0" to your network adapter.
Cheers
Code:
#!/usr/bin/env python
#
# licensed under GNU General Public License version 2
#
import sys
import traceback
import gobject
import dbus
import dbus.decorators
import dbus.mainloop.glib
import os
def catchall_signal_handler(*args, **kwargs):
print ("Caught signal: "
+ kwargs['member'])
if args[0] >= 6: #vpn disconnect (6) or failure (7)
print ("Killing internet connection...")
#set eth0 to your network adapter
os.system('ifconfig eth0 down')
#if you are using python 3 no raw_input() exists so use input()
raw_input("Press Enter to enable your network adapter...")
#set eth0 to your network adapter
os.system('ifconfig eth0 up')
print ("Your network adapter has been enabled.")
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
print ("Monitoring your VPN connection...")
bus = dbus.SystemBus()
#lets make a catchall
bus.add_signal_receiver(catchall_signal_handler, signal_name='VpnStateChanged', interface_keyword='dbus_interface', member_keyword='member')
loop = gobject.MainLoop()
loop.run()
Bookmarks