节约网络流量的方案和NetworkMonitor提示小程序

Firefox安装节省流量方案的插件:

Adblock: 拦截网页广告的下载
Flashblock: 拦截Flash自动下载播放 ,通过鼠标点击来下载播放Flash程序。
ImgLikeOpera: 拦截图片的自动下载显示,通过鼠标点击来加载需要下载显示的图片。

NetworkMonitor小程序:

随时查看使用流量:

当使用超过1MB流量时,显示警告信息:

使用/proc/net/netstat里提供的信息来得到本次系统启动以来的流量统计。

Python代码:

#!/usr/bin/python

import pynotify, pygtk
pygtk.require("2.0")
import gtk, gobject
import threading, traceback, time

class NetworkMonitor():
    def __init__(self):
        self.tooltip = "Network Monitor\nWait..."
        self.total = 0
        self.init_icon()
        self.notifier = pynotify.Notification("Network Monitor")
        self.update()
        gobject.timeout_add(3000, self.update)
        
    def right_click(self, icon, button, time):
        self.menu.popup(None, None, None, button, time)
        return False
        
    def init_icon(self):
        self.icon = gtk.status_icon_new_from_stock(gtk.STOCK_FIND)
        self.icon.set_title("Network Monitor")
        self.icon.set_tooltip(self.tooltip)
        self.icon.set_visible(True)
        # Add a menu for the icon
        self.menu = gtk.Menu()
        quit = gtk.MenuItem("Quit")
        quit.connect("activate", gtk.main_quit)
        self.menu.append(quit)
        self.menu.show_all()
        self.icon.connect("popup-menu", self.right_click)
        
    def update(self):
        info = file("/proc/net/netstat", "rb").read().split(" ")
        outBytes = float(info[-5])/(1024*1024)
        inBytes = float(info[-6])/(1024*1024)
        total = outBytes + inBytes
        self.tooltip = "In: %0.2fMB  Out: %0.2fMB\nTotal: %0.2fMB" % (inBytes, outBytes, total)
        self.icon.set_tooltip(self.tooltip)
        if int(total) - int(self.total) >= 1:
            self.total = int(total)
            self.notifier.update("Network Monitor", self.tooltip, "dialog-warning")
            self.notifier.show()
        return True

if __name__ == "__main__":
    nm = NetworkMonitor()
    gtk.main()

保存上述代码到本地的bin目录,设置为可执行文件。然后添加到GNOME的启动项,就可以伴随登录的时候启动程序:

节约网络流量的方案和NetworkMonitor提示小程序》有18个想法

    1. Xiaoxia 文章作者

      o(∩∩)o…哈哈,不需要任何修改就可以使用的。而且提示更加美观可爱!kubuntu也可以把它添加为自启动程序。
      我这几天就在用kubuntu11.04,这是我笔记本上到系统。我移动硬盘上装到是ubuntu10.10.

      回复
      1. 元谷

        我比较喜欢xubuntu!对于lubuntu还行!lubuntu的中文似乎支持的很好,至于edubuntu和kubuntu还没有用过,不好评论!ubuntu11.04.,我表示不喜欢他的桌面!

        回复
  1. 新安

    hello,what’s the plugin of your code Highlighter’s name?
    I search a lot of code-Highlighter wordpress plugins,but I still haven’t find a proper one.
    can you show me the plugin’s url?Thank you!

    回复
    1. Xiaoxia 文章作者

      i don’t know if there’s any specific network statistics tool for ipv6.
      if you want QOS on ipv6 or to block connections or manipulate packets, try ip6tables 🙂

      回复

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据