Community discussions

MikroTik App
 
Bernhard
just joined
Topic Author
Posts: 9
Joined: Mon Apr 12, 2021 4:42 pm
Location: Vienna / Austria

Script to display clients in WLAN (with hostname and accesspoint)

Thu Sep 30, 2021 7:05 pm

Hi all,
i wrote a script, which aggregates 4 tables to display the registered Clients in CAPsMAN with DHCP hostname and the identity of the access-point.
Looks like this:
[user@router] > /system script run wlan 
MAC                 IP              Client      AP             Signal TX Rate                RX Rate                Uptime          Packets             Bytes               Interface
FF:FF:FF:FC:89:2E   192.168.1.250   Client01    AccessPoint01  -58    173.3Mbps-20MHz/2S/SGI 12Mbps                 1d05:21:12.980  189458,116674       52138685,23855249   cap13
FF:FF:FF:11:3E:9C   192.168.1.251   Client02    AccessPoint02  -54    173.3Mbps-20MHz/2S/SGI 12Mbps                 1d05:16:53.180  201567,125334       53921014,16576701   cap14
Here the script:
:global fill do={
	:local VAR $1;
	:local LEN $2;
	:local CHAR $3;
	:local lenVAR [:len $VAR];
	:for i from=1 to=($LEN-[:len $VAR]) step=1 do={
		:set VAR ("$VAR" . $CHAR);
	}
	:return $VAR;
}

:put ([$fill "MAC" 20 " "].[$fill "IP" 16 " "].[$fill "Client" 12 " "].[$fill "AP" 15 " "].[$fill "Signal" 7 " "].[$fill "TX Rate" 23 " "].[$fill "RX Rate" 23 " "].[$fill "Uptime" 16 " "].[$fill "Packets" 20 " "].[$fill "Bytes" 20 " "]."Interface");
:foreach i in=[/caps-man registration-table find .id] do={
   :local locMAC    [/caps-man registration-table get $i mac-address];
   :local locInt    [/caps-man registration-table get $i interface];
   :local locSignal [/caps-man registration-table get $i rx-signal];
   :local loctxRate [/caps-man registration-table get $i tx-rate];
   :local locrxRate [/caps-man registration-table get $i rx-rate];
   :local locUptime [/caps-man registration-table get $i uptime];
   :local locPack   [/caps-man registration-table get $i packets];
   :local locBytes  [/caps-man registration-table get $i bytes];
   :local locRadMAC [/caps-man interface get [/caps-man interface find name=$locInt] radio-mac];
   :local locCAP    [/caps-man radio get [/caps-man radio find radio-mac=$locRadMAC] remote-cap-identity];
   :local locIP     [/ip dhcp-server lease get [/ip dhcp-server lease find mac-address=$locMAC] address];
   :local locName   [/ip dhcp-server lease get [/ip dhcp-server lease find mac-address=$locMAC] host-name];
   :put ([$fill $locMAC 20 " "].[$fill $locIP 16 " "].[$fill $locName 12 " "].[$fill $locCAP 15 " "].[$fill $locSignal 7 " "].[$fill $loctxRate 23 " "].[$fill $locrxRate 23 " "].[$fill $locUptime 16 " "].[$fill $locPack 20 " "].[$fill $locBytes 20 " "]."$locInt");
}
Best regards
Bernhard

Who is online

Users browsing this forum: qatar2022 and 25 guests