6 network.lua - wmiirc-lua plugin for monitoring network interfaces
10 -- in your wmiirc.lua:
11 wmii.load_plugin("network")
16 For the options you can define something like
18 wmii.set_conf("network.interfaces.wired", "eth0")
19 wmii.set_conf("network.interfaces.wireless", "wlan0")
21 which will show informations about the wireless device wlan0 and
22 the non-wireless device eth0
30 Jan-David Quesel <jdq@gmx.net>
32 =head1 LICENCE AND COPYRIGHT
34 Copyright (c) 2008, Jan-David Quesel <jdq@gmx.net>
36 This is free software. You may redistribute copies of it under the terms of
37 the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
38 is NO WARRANTY, to the extent permitted by law.
43 local wmii
= require("wmii")
44 local io
= require("io")
45 local string = require("string")
51 wmii
.set_conf("network.interfaces.wired", "eth0")
52 wmii
.set_conf("network.interfaces.wireless", "")
55 -- ------------------------------------------------------------
59 local function _command ( cmd
)
62 wmii
.log( "about to run " .. cmd
)
63 local file
= io
.popen( cmd
)
64 local status
= file
:read("*a")
68 --return status:match("[^\n]*")
74 local function create_device_string(device
)
75 local ip
= "ifconfig " .. device
["name"]
76 local ipstr
= _command(ip
)
77 ipstr
= ipstr
:gmatch("inet addr:([0-9.]+)")()
78 if ipstr
== nil or ipstr
== "" then
79 txt
= device
["name"] .. ": down"
81 ipstr
= ipstr
.sub(ipstr
, 1, ipstr
.len(ipstr
))
82 txt
= device
["name"] .. ": " .. ipstr
83 if device
["wireless"] then
84 local ssid
= "iwconfig " .. device
["name"]
85 local str_ssid
= _command(ssid
)
86 str_ssid
= str_ssid
:gmatch("ESSID:\"(.*)\"")()
87 txt
= txt
.. "@(" .. str_ssid
.. ")"
91 device
["widget"]:show(txt
)
95 local function generate_lists()
96 wmii
.log("generating interface list")
97 local strings
= wmii
.get_conf("network.interfaces.wired")
98 for str
in strings
:gmatch("%w+") do
99 devices
[#devices
+1] = {
101 widget
= wmii
.widget
:new ("350_network_" .. str
),
104 wmii
.log("found " .. str
)
106 local strings
= wmii
.get_conf("network.interfaces.wireless")
107 for str
in strings
:gmatch("%w+") do
108 devices
[#devices
+1] = {
110 widget
= wmii
.widget
:new ("350_network_" .. str
),
113 wmii
.log("found " .. str
)
118 local function update ()
119 for _
,device
in pairs(devices
) do
120 create_device_string(device
)
124 local function network_timer ( timer
)
125 if #devices
== 0 then
133 timer
= wmii
.timer
:new (network_timer
, 1)