OpenWrt Forum Archive

Topic: Display connected clients and processor load

The content of this topic has been archived on 10 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I want to be able to do 2 things.... i want to display all the connected clients (mac address, ip, etc) on my lan or wan and I also want to be able to display the CPU load... how do i do this?

Where do you want to display it?

"cat /proc/net/ip_conntrack" will show you details of active connections through your WRT (there are scripts available that will parse the output into something more readable).  Is that the sort of info you're after?

"uptime" and "top" will display processor load.

Cheers,
Martin.

wl assoclist

"brctl showmacs br0" will show you all the MAC addresses seen by bridge interface br0, i.e. devices which have been sending at layer 2. If you are running the default config where br0 connects to both the LAN and wifi ports, this is probably the closest you will get to a "list of clients". It will show only MAC addresses.

"arp -n" will show you the ARP table; this shows machines to which the Wrt itself has sent or forwarded IP datagrams at layer 3. If the Wrt is acting as a router, e.g. your LAN clients are sending traffic via the Wrt and out through the WAN interface, they will appear here. It will show both IP and MAC addresses. LAN clients which are only sending traffic directly to each other, or to Wifi clients, won't appear.

Both sets of tables will time out entries after a certain amount of time.

"wl assoclist" will show the MAC addresses of wireless clients which have associated to you (assuming you are an access point). These will remain for as long as the client remains associated, AFAIK.

If you are running a DHCP server on the Wrt, then I think "cat /tmp/dhcp.leases" will show you the IP addresses/MAC addresses to whom DHCP has allocated an address. (I've not tested this, as my Wrt is not a DHCP server)

Is any of those close to what you were looking for?

those were all what i'm looking for... i for now just wanted to kno whos on my network, but in the future, i may want to write a script to do something with that info

btw.. where can i get a script to format cat /proc/net/ip_conntrack into a more readable list?

Edit: One thing i forgot to ask for was how do i show the bandwidth usage on my vlan0 (WAN interface). I want to write a script to change the color of the cisco led when bandwidth goes up. Also for this script, i want to turn off the light when there's no connection. So how would I check for internet connectivity?

(Last edited by eatnumber1 on 20 Feb 2006, 21:31)

For bandwidth: look at the interface received/transmitted byte counters, as shown by ifconfig vlan0 or cat /proc/net/dev (the latter, with one row per interface and each counter in a separate column, is easier to parse)

For reformatting data like this: learn how to use awk, or install the microperl package and learn that. Having a 'real' Linux box nearby, so you can read the manpages, is helpful (although note that busybox's awk is going to be cut down from a full awk). Google is your friend too.

For detecting when there's a connection, that depends what you want to do. Do you want to test if the link is physically unplugged, or the remote end has been powered down? That means querying the status of each ethernet port connected to the switch, which you can do using robocfg (separate package, install using ipkg)

root@OpenWrt:~# robocfg show
Switch: enabled
Port 0(W):  DOWN 0x0000  enabled stp: none vlan: 1 mac: 00:00:00:00:00:00
Port 1(4):  DOWN 0x0000  enabled stp: none vlan: 2 mac: 00:00:00:00:00:00
Port 2(3):  10HD 0x0000  enabled stp: none vlan: 0 mac: 00:00:00:00:00:00
Port 3(2):  DOWN 0x0000  enabled stp: none vlan: 0 mac: 00:00:00:00:00:00
Port 4(1):  DOWN 0x0000  enabled stp: none vlan: 0 mac: 00:00:00:00:00:00
Port 5(C): 100FD 0x0000  enabled stp: none vlan: 0 mac: 00:11:d8:01:cc:09
VLANs: BCM536x enabled mac_check mac_hash
vlan0: 2 3 4 5t
vlan1: 0 5t
vlan2: 1 5t

'DOWN' indicates that the port is inactive at layer 1; here you can see port 2 is plugged in (labelled "LAN 3" on the box), and is communicating at 10Mbps half duplex; the others are disconnected (port 5 is the internal interconnect to the processor). However, most Wrt boxes have port status lights on the front for each port anyway, so I doubt you'd want to duplicate that.

If you want to test whether the upstream connection is actually usable, then you could write a script to (a) check that the interface has picked up an IP address via DHCP (using ifconfig for example), and/or (b) periodically ping something upstream, and see if you get a response or not.

(Last edited by candlerb on 21 Feb 2006, 10:04)

candlerb wrote:

If you want to test whether the upstream connection is actually usable, then you could write a script to (a) check that the interface has picked up an IP address via DHCP (using ifconfig for example), and/or (b) periodically ping something upstream, and see if you get a response or not.

That's exactly what I want to do, but i don't know how to use the ifconfig command very well, nor do I know how to format text output.

Getting to know a desktop Linux box will help you learn the commands, which are generally the same on OpenWRT but with fewer options.

You can learn awk or perl for matching parts of lines and extracting the data you're interested in:

root@OpenWrt:~# ifconfig br0 | microperl -ne 'print "$1\n" if /inet addr:([0-9.]+)/'
192.168.2.1
root@OpenWrt:~#

Get a book on Perl or Awk if you want to learn how this works - a useful life skill anyway. Check out the O'Reilly series of books - or do some research on Google.

Also, a lot of the ifconfig display is actually taken from information published by the kernel under /proc, so in some cases you can look for a file which contains the information you're interested in.

candlerb wrote:

For bandwidth: look at the interface received/transmitted byte counters, as shown by ifconfig vlan0 or cat /proc/net/dev (the latter, with one row per interface and each counter in a separate column, is easier to parse)

I don't want to know overall data transmitted. I want to know how much data is being transmitted at this moment so I can make the CISCO LED reflect that.

(Last edited by eatnumber1 on 22 Feb 2006, 07:39)

So you take the difference between the value now and the value it had one or N seconds ago, and you get the number of bytes transmitted or received in a fixed timeperiod, which you compare to a threshold.

You really have to do it this way, because otherwise whenever a single packet is sent, your bandwidth is instantaneously 100Mbps while the packet is being sent, and then drops back to 0 in the gap between packets. This is true, but not particularly useful. If you want to have some idea of average usage over some time period T, it's up to you to choose a value of T which makes sense for you.

The discussion might have continued from here.