Community discussions

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

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

Mon Oct 04, 2021 3:47 pm

Hello community - in CAPsMAN you can list all registered clients on all CAP Interfaces. You see MAC of client and Interface.
What you don't see, is the DHCP name of the client and whick access point it is on.
I wrote a script to display exact this information. What you will get is:
MAC                IP               Client      AP              Signal TX Rate    RX Rate    Uptime        Bytes               Packets             Interface
FF:FF:FF:11:3E:9C   Client01    AccessPoint01   -53    117Mbps    12Mbps     5d01:54:54    68431014,22847922   286257,200633       cap14
FF:FF:FF:11:76:9A   Client02    AccessPoint03   -75    16Mbps     12Mbps     1d10:54:53    68123014,54347922   286257,200633       cap12
This is my script:
:global fill do={
	# this function fills up a string with a char up to a length - its used to make a tabular view of values
	# 3 parameters: #1 string to fill
	#               #2 length to fill up (or cut down)
	#               #3 char used to fill up (or as delimiter when cutting)
	# if the length of the string is more than the parameter length-1, the string will be cut by length-1 and one char will be appended as delimiter
	:local STR $1;
	:local LEN $2;
	:local CHAR $3;
	:if ([:len $STR] >= $LEN) do={
		# string has to be cut
		:set STR ([:pick $STR 0 ($LEN-1)].$CHAR);
	} else {
		# string has to be filled up to length
		:for i from=1 to=($LEN-[:len $STR]) step=1 do={
			:set STR ("$STR" . $CHAR);
	:return $STR;

:put ([$fill "MAC" 19 " "].[$fill "IP" 17 " "].[$fill "Client" 12 " "].[$fill "AP" 16 " "].[$fill "Signal" 7 " "].[$fill "TX Rate" 11 " "].[$fill "RX Rate" 11 " "].[$fill "Uptime" 14 " "].[$fill "Bytes" 20 " "].[$fill "Packets" 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];
	# reduce to relevant data: "173.3Mbps-20MHz/2S/SGI" --> "173.3Mbps"
	:if ([:find $loctxRate "-" -1] > 0) do={ :set loctxRate [:pick $loctxRate 0 [:find $loctxRate "-" -1]];}
	:local locrxRate [/caps-man registration-table get $i rx-rate];
	:if ([:find $locrxRate "-" -1] > 0) do={ :set locrxRate [:pick $locrxRate 0 [:find $locrxRate "-" -1]];}
	:local locUptime [/caps-man registration-table get $i uptime];
	:set locUptime   [:pick $locUptime 0 [:find $locUptime "." -1]];
	:local locBytes  [/caps-man registration-table get $i bytes];
	:local locPack   [/caps-man registration-table get $i packets];
	: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 19 " "].[$fill $locIP 17 " "].[$fill $locName 12 " "].[$fill $locCAP 16 " "].[$fill $locSignal 7 " "].[$fill $loctxRate 11 " "].[$fill $locrxRate 11 " "].[$fill $locUptime 14 " "].[$fill $locBytes 20 " "].[$fill $locPack 20 " "]."$locInt");
Best regards

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests