[ask] how to query all "device" shown in web ui /cgi-bin/luci/admin/network/network?

some commands i've tried :
uci show network | grep "=device$" = only shows already configured device
ls /sys/class/net/ = includes additional device like lo,ip6tnl, etc
grep device /etc/config/network = includes additional device lo and doesn't include wireless device like wlan0, etc

the purpose is i'm makig a script to auto-configure the whole system at first boot
my test script (still contains lo which i don't want to touch) :

#!/bin/bash

x() {
        local network_devices
        for network_interface in $(uci -X show network | grep "=interface$" | awk -F'=' '{print $1}');do
                local network_device=$(uci get ${network_interface}.device 2>/dev/null)
                if [[ -n ${network_device} ]] && [[ ! ${network_devices[*]} =~ ${network_device} ]];then
                        network_devices+=${network_device}
                        echo "${network_device[*]}"
                fi
        done
}

x
exit 0

i know i can add [[ "${network_device}" != "lo" ]] to the test script, but i'm curious if there's a proper way than this

. /lib/functions.sh
. /lib/functions/network.sh
_process_iface() {
local dev
network_get_device dev "$1"
echo "$dev"
}
config_load network
config_foreach _process_iface interface

the output is (include those extra gap):

root:~# ./test
lo
br-lan
eth1




root:~#

while what shown on web interface is :

expectation (according to the screenshot):

root:~# ./test
br-lan
eth0
eth1
wlan1
root:~#

I see. For this, I'd look into source of that page to see what it's querying. I'd imagine it's a ubus/rpcd call of sorts, I just don't know what would list devices like that.

maybe use the output of ip address show
e.g.

ip a s | grep "<BROADCAST\|POINTOPOINT" | cut -d":" -f2 | while read network_devices; do
  echo $network_devices
done

my system output:

wan
br-lan
wg0
br-guest
phy0-ap0
phy1-ap0
phy0-ap1
phy1-ap1
1 Like

well done, thank you

for path in /sys/class/net/*; do
  echo $(basename $path)
done

that looks elegan but the outputs have lo, ip6tnl0,sit0 which doesn't match what shown in web ui

br-lan
eth0
eth1
ip6tnl0
lo
sit0
wlan1

The ui actively filters certain, well known devices. That list of device name (patterns) to exclude is hardcoded though. See https://github.com/openwrt/luci/blob/master/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js#L1286

To roughly replicate that logic, you'd need something like that:

ubus call luci-rpc getNetworkDevices | \
    jsonfilter -e '@[@.name != "lo" && @.wireless = false && @.up = true].name'

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.