Network Interface Name Detection in Conky

Once-off Conky config for network graphs

When one changes connection type (say, from ethernet to Wi-Fi), the interface name changes (e.g. eth0wlan1). To avoid changing Conky config file all the time, here’s a little Lua function for finding the network interface name.

function findInterface()
    local handle = io.popen('ip a | grep "state UP" | cut -d: -f2 | tr -d " "')
    local result = handle:read('*a'):gsub('\n$','')
    handle:close()
    return result
end
  1. ip a gives everything about connection info. Each entry looks like

     3: wlp3s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    
  2. Grep the “state UP” and extract the second field, using : as a delimiter. Trim off the spaces around.

    [Read More]
Conky  Lua