Lan network widget

This is a simple lan network plugin for statusbar. On click it will toggle your lan connection. It is pulling information from /sys/class/net/"..adapter.."/operstate to get current status of connection. That happens every 30 seconds. After you change lan state it will check it much more often for a wile. That could be a good idea to make widget which receives signal for system, that network state is changed. Anyway. That's it

=Installation=

The widget
Add the following code into your personal rc.lua file: --all settings are made in next 3 lines lan_enable_net_path="/home/user/bin/net.sh" lan_disable_net_path="/home/user/bin/anet.sh" lan_interface="eth0"

lan_short_timer = timer({timeout = 1}) lan_short_timer:connect_signal("timeout", function	if lan_connected == lan_need_state		then		lan_short_timer:stop;		end    laninfo(lan_interface) end) --lan_timer:start

function laninfo(adapter) local f = io.open("/sys/class/net/"..adapter.."/operstate") local isconnected = f:read if isconnected == "down" then lanwidget.tooltip:set_text("network is not connected") lanwidget:set_markup(' X ') lan_connected=0 else lanwidget.tooltip:set_text("network is connected") lanwidget:set_markup(' + ') lan_connected=1 end end

lanwidget = wibox.widget.textbox lanwidget.set_align("right") lanwidget.tooltip = awful.tooltip ({ objects = { lanwidget } }) lanwidget_lan=0 lanenable = terminal .. " -e " .. lan_enable_net_path landisable = terminal .. " -e " .. lan_disable_net_path

lanwidget:buttons (awful.util.table.join ( awful.button ({}, 1, function		lan_short_timer:start;		if lan_connected==0			then			awful.util.spawn (lanenable)			lan_need_state=1;			else			lan_need_sate=0;			awful.util.spawn (landisable)			end		laninfo(lan_interface)	end), awful.button ({}, 3, function		awful.util.spawn (editor .." ".. lan_enable_net_path)		awful.util.spawn (editor .." ".. lan_disable_net_path)	end) ))

laninfo(lan_interface)

lan_timer = timer({timeout = 10}) lan_timer:connect_signal("timeout", function    laninfo(lan_interface) end) lan_timer:start Then add alsawidget.bar to your wibox layout(s). right_layout:add(lanwidget)

Setting up system
You must have shell scripts in place to use this widget. I used: my /home/user/bin/net.sh contains ip addr add 188.227.110.45/255.255.255.0 dev enp2s0 ip route add default via 188.227.110.1 echo "nameserver 85.235.193.2" >> /etc/resolv.conf ip link set dev enp2s0 up ip addr add 188.227.110.45/255.255.255.0 dev enp2s0 ip route add default via 188.227.110.1 echo "nameserver 85.235.193.2" >> /etc/resolv.conf ip link set dev enp2s0 up my /home/user/bin/anet.sh contains ip link set dev enp2s0 down But to make your scripts work from user account, you have to change your permissions for ip utility or shell script. chown root:users doit chmod u=rxs,g=x,o= doit =Notes=
 * None at the moment.