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

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

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

NetworkMonitor小程序:

随时查看使用流量:

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

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

Python代码:

  1. #!/usr/bin/python  
  2.   
  3. import pynotify, pygtk  
  4. pygtk.require("2.0")  
  5. import gtk, gobject  
  6. import threading, traceback, time  
  7.   
  8. class NetworkMonitor():  
  9.     def __init__(self):  
  10.         self.tooltip = "Network Monitor\nWait..."  
  11.         self.total = 0  
  12.         self.init_icon()  
  13.         self.notifier = pynotify.Notification("Network Monitor")  
  14.         self.update()  
  15.         gobject.timeout_add(3000self.update)  
  16.           
  17.     def right_click(self, icon, button, time):  
  18.         self.menu.popup(NoneNoneNone, button, time)  
  19.         return False  
  20.           
  21.     def init_icon(self):  
  22.         self.icon = gtk.status_icon_new_from_stock(gtk.STOCK_FIND)  
  23.         self.icon.set_title("Network Monitor")  
  24.         self.icon.set_tooltip(self.tooltip)  
  25.         self.icon.set_visible(True)  
  26.         # Add a menu for the icon  
  27.         self.menu = gtk.Menu()  
  28.         quit = gtk.MenuItem("Quit")  
  29.         quit.connect("activate", gtk.main_quit)  
  30.         self.menu.append(quit)  
  31.         self.menu.show_all()  
  32.         self.icon.connect("popup-menu"self.right_click)  
  33.           
  34.     def update(self):  
  35.         info = file("/proc/net/netstat""rb").read().split(" ")  
  36.         outBytes = float(info[-5])/(1024*1024)  
  37.         inBytes = float(info[-6])/(1024*1024)  
  38.         total = outBytes + inBytes  
  39.         self.tooltip = "In: %0.2fMB  Out: %0.2fMB\nTotal: %0.2fMB" % (inBytes, outBytes, total)  
  40.         self.icon.set_tooltip(self.tooltip)  
  41.         if int(total) - int(self.total) >= 1:  
  42.             self.total = int(total)  
  43.             self.notifier.update("Network Monitor"self.tooltip, "dialog-warning")  
  44.             self.notifier.show()  
  45.         return True  
  46.   
  47. if __name__ == "__main__":  
  48.     nm = NetworkMonitor()  
  49.     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 🙂

      回复

回复 Chord 取消回复

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

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