12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- local list = util.exec('batctl if')
- local wireless = {}
- local tunnel = {}
- local other = {}
- local function get_address(t, ifname)
- pcall(
- function()
- table.insert(t, util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address')))
- end
- )
- end
- local function is_wireless(ifname)
- local type = fs.stat('/sys/class/net/' .. ifname .. '/wireless', 'type')
- return type == 'directory'
- end
- local function is_tuntap(ifname)
- local type = fs.stat('/sys/class/net/' .. ifname .. '/tun_flags', 'type')
- return type == 'regular'
- end
- local function nil_table(t)
- if next(t) ~= nil then
- return t
- else
- return nil
- end
- end
- for _, line in ipairs(util.split(list)) do
- local ifname = line:match('^(.-):')
- if ifname ~= nil then
- if is_wireless(ifname) then
- get_address(wireless, ifname)
- elseif is_tuntap(ifname) then
- get_address(tunnel, ifname)
- else
- get_address(other, ifname)
- end
- end
- end
- return {
- wireless = nil_table(wireless),
- tunnel = nil_table(tunnel),
- other = nil_table(other)
- }
|