是否可以在 VPN 连接时添加通知消息?

dig*_*ail 5 notification 10.04 vpn

我正在使用 Ubuntu 10.04 并且我用来连接到 pptp VPN,一切正常,当我开始我的 VPN 连接时,我可以从 NetworkManager 图标看到连接正在进行中,我可以看到连接在什么时候打开网络图标获得小锁。

带有网络连接和 VPN 锁定图标的通知区域

是否可以添加通知气球,就像我在网络连接建立时看到的那样?

eth0 连接建立通知气球

Ps 如果连接失败或掉线,通知出来是这样的: VPN失败

Joã*_*nto 3

这更像是一个黑客,但应该有效(对我有用)。

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 Code Online (Sandbox Code Playgroud)

运行它:

python vpn-notify.py
Run Code Online (Sandbox Code Playgroud)

建立 VPN 连接。