Xiaoxia[PG]

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

Internet、Linux18 条评论

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

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

NetworkMonitor小程序:

随时查看使用流量:

Screenshot-152

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

Screenshot-142

使用/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的启动项,就可以伴随登录的时候启动程序:

Screenshot-16

18 条评论

    1. wf同学为何不给自己设置一个头像呢?去gravatar.com

  1. 哈哈..小虾这样可折腾了呀~怕超流量得时不时查看用了多少...这样心有不安

  2. 原来pygtk这么简洁,可以玩玩啊

    1. 啊哈,原来是我上次上传的图在G这条没通过!!!PG、R、X都通过了!现在重新上传张就好了!

  3. 留言是种美德,写点什么…

    1. 回复是种美德,回点什么...

  4. 对于Kubuntu这类版本,又有什么办法呢?

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

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

        1. 恩,我看了同学使用,感觉我也不是很习惯。kde到比较舒服!

  5. it's only for gnome2...

    希望有gnome3版本的呃。其实gnome3用的也是javascript,比这个差不了多少。

  6. 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. Google Syntax Highlighter for WordPress
      The website is: http://wordpress.org/extend/plugins/google-syntax-highlighter
      Enjoy it!

  7. are there any ipv6 network monitor tools have the Statistics function or any tools can block some ipv6 connect? Thank you!

    1. 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 🙂

  8. 嘿,这个是什么主题啊,很漂亮的说,elementary?

发表评论

评论会经过自动审核,链接请勿超过 3 个。