5

I'm using Ubuntu 10.04 and I use to connect to a pptp VPN, everything works perfectly, when i start my VPN connection I can see that the connection is in progress from the NetworkManager icon, and I can see that the connection is on when the Network icon gets the small lock.

notification area with network connection and vpn lock icon

Is it possible to add a notification ballon, like the one I see when the network connection is estabilished?

eth0 connection estabilished notification baloon

P.s if the connection fail or is dropped, the notification cames out like this: vpn failed

5

2 Answers 2

3

This is more like a hack but should work (works for me).

vpn-notify.py:

import gtk
import pynotify
import dbus
from dbus.mainloop.glib import DBusGMainLoop

def vpn_connection_handler(*args, **keywords):
    state = args[0].get('State',0)
    if state == 2:
        n = pynotify.Notification ("VPN", "Connection established")
        n.show()


pynotify.init ("icon-summary-body")


dbus_loop = DBusGMainLoop()

system_bus = dbus.SystemBus(mainloop=dbus_loop)
system_bus.add_signal_receiver(vpn_connection_handler,
    dbus_interface="org.freedesktop.NetworkManager.VPN.Connection",
    signal_name="PropertiesChanged")

gtk.gdk.threads_init()
gtk.main()

Run it with:

python vpn-notify.py

Establish the VPN connection.

2
0

Here is code which tells if you are connected to VPN or NOT.

**Note:** *IPv4 adress of the machine on VPN might change each time you connect to VPN.*

    import subprocess
    host = '**.***.***.***' 
    #IPv4 should be string ''
    #IPv4 Address (while connected to VPN in command prompt type: ipconfig",
    copy IPv4 Address digits and paste as "host = ", 
    #IPv4 Address. changes each time we freshly connect to VPN. )
    ping = subprocess.Popen(["ping.exe","-n","1","-w","1",host],stdout = subprocess.PIPE).communicate()[0]
    if ('unreachable' in str(ping)) or ('timed' in str(ping)) or ('failure' in str(ping)):
        ping_chk = 0
    else:
        ping_chk = 1 

    if ping_chk == 1:
         print ("VPN Connected")
    else:
        print ("VPN Not Connected")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .