Community discussions

MikroTik App
 
mfrayyan
just joined
Topic Author
Posts: 12
Joined: Wed Mar 16, 2022 12:50 pm

how can save mac address in a comment after login

Wed Mar 16, 2022 12:55 pm

how can save mac address in a comment after login , hotspot user
thanks
 
JaviGL93
just joined
Posts: 12
Joined: Thu Mar 03, 2022 7:13 pm

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 2:51 am

#here we exclude default-trial user or else the script won't excecute the last line
:foreach i in=[/ip hotspot user find where name!=default-trial] do={
:local uptime [/ip hotspot user get number=$i uptime];
#if an user have 00:00:00 uptime means it's not connected right? then...
:if ($uptime=00:00:00) do={
:log info "User$i Not Connected"} else={
#i don't know where do you want to add the comments so i did it right there in /ip hotspot user just as an example
:put [/ip hotspot user set number=$i comment=[/ip hotspot user get number=$i mac-address]]}
}

hope it helps ;)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 8:19 am

Cleaned up the script. Code tags, tabs, if section and removed not needed ;
:foreach i in=[/ip hotspot user find where name!=default-trial] do={
	:local uptime [/ip hotspot user get number=$i uptime]
	#if an user have 00:00:00 uptime means it's not connected right? then...
	:if ($uptime=00:00:00) do={
		:log info "User$i Not Connected"
	} else={
		#i don't know where do you want to add the comments so i did it right there in /ip hotspot user just as an example
		:put [/ip hotspot user set number=$i comment=[/ip hotspot user get number=$i mac-address]]
	}
}
Shorten some and set the comment, not just show it:
/ip hotspot user 
:foreach i in=[find where name!=default-trial] do={
	:local uptime [user get number=$i uptime]
	#if an user have 00:00:00 uptime means it's not connected right? then...
	:if ($uptime=00:00:00) do={
		:log info "User$i Not Connected"
	} else={
		set number=$i comment=[get number=$i mac-address]]
	}
}
 
mfrayyan
just joined
Topic Author
Posts: 12
Joined: Wed Mar 16, 2022 12:50 pm

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 9:37 am

thank you I'll try to this script

but I have another script use it in a (On login) tab in this path (( ip > hotspot > User Profiles > Scripts > On login ))
:local a $user
:local m [/ip hotspot active get [find user=$a] mac-address]
:log info message=("Prueba: ;$a; ;$m;");
/ip hotspot user set $a mac=$m;
but this script add MAC in MAC address field not in a comment, Can we make some changes rules in this script so that put MAC in a comment?

thanks so much
 
JaviGL93
just joined
Posts: 12
Joined: Thu Mar 03, 2022 7:13 pm

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 9:57 am

thank you I'll try to this script

but I have another script use it in a (On login) tab in this path (( ip > hotspot > User Profiles > Scripts > On login ))
:local a $user
:local m [/ip hotspot active get [find user=$a] mac-address]
:log info message=("Prueba: ;$a; ;$m;");
/ip hotspot user set $a mac=$m;
but this script add MAC in MAC address field not in a comment, Can we make some changes rules in this script so that put MAC in a comment?

thanks so much
if On login works as i think it does, you´ll just need to change this:
/ip hotspot user set $a mac=$m;

for this:
/ip hotspot user set $a comment=$m; (cause you mean a comment right there in /ip hotspot user right?)

let us know.

Thanks @Jotne but the shortened version of my script didn't worked out for me, even when i added : and [ to --> set number=$i comment=[get number=$i mac-address]]
 
mfrayyan
just joined
Topic Author
Posts: 12
Joined: Wed Mar 16, 2022 12:50 pm

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 11:24 am

thank you I'll try to this script

but I have another script use it in a (On login) tab in this path (( ip > hotspot > User Profiles > Scripts > On login ))
:local a $user
:local m [/ip hotspot active get [find user=$a] mac-address]
:log info message=("Prueba: ;$a; ;$m;");
/ip hotspot user set $a mac=$m;

but this script add MAC in MAC address field not in a comment, Can we make some changes rules in this script so that put MAC in a comment?

thanks so much
if On login works as i think it does, you´ll just need to change this:
/ip hotspot user set $a mac=$m;

for this:
/ip hotspot user set $a comment=$m; (cause you mean a comment right there in /ip hotspot user right?)

let us know.

Thanks @Jotne but the shortened version of my script didn't worked out for me, even when i added : and [ to --> set number=$i comment=[get number=$i mac-address]]
thaaaaaaaaaanks so much @JaviGL93
exactly this is what I wanted, and used this script and do what I wanted

another question please

the script added MAC in a comment but deleted old comment, Is it possible to add comment not replace comment?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 4:29 pm

...
Last edited by rextended on Fri Mar 18, 2022 1:36 am, edited 8 times in total.
 
JaviGL93
just joined
Posts: 12
Joined: Thu Mar 03, 2022 7:13 pm

Re: how can save mac address in a comment after login

Thu Mar 17, 2022 5:40 pm


another question please

the script added MAC in a comment but deleted old comment, Is it possible to add comment not replace comment?
You could save previous comment and then :set $mac and $previous_comment together

:local previous_comment [/ip hotspot user get $a comment]
/ip hotspot user set $a comment="$previous_comment --> $m"

*btw if an user mac address change the comment will show old and new mac address too :(
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 1:36 am

All can be reduced to:
:local mac $"mac-address"
:log info "Prueba: $user $mac"
/ip hotspot user
:local comentario [get $user comment]
set $user comment="$mac - $comentario"
And is better add previous comment later than first, for read reason...

And I think you want keep comments for history of MACs?
 
mfrayyan
just joined
Topic Author
Posts: 12
Joined: Wed Mar 16, 2022 12:50 pm

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 4:17 pm

yes, I used last script and old comment still exists :) ,,,,,,,,,,, working fine

@JaviGL93 thanks
and
@rextended thanks so much for reduce script :)

On the mention of Date,,, I have another question :?

before write this post I wanted to have script save comment contain MAC and date and time user login
Can this script be developed to contain MAC and time (year, month, day, hour and minute) after user logged?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 5:18 pm

yes, but the comment over time can increase too much in size...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 5:24 pm

The date is "like" ISO format: "00:AA:BB:CC:DD:EE 2022-03-18 16:25"
:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$($arrMonths->[:pick $curdatetime 0 3])-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")

:local mac $"mac-address"
:log info "Prueba: $user $mac"
/ip hotspot user
:local comentario [get $user comment]
set $user comment="$mac $ldate - $comentario"
Last edited by rextended on Fri Mar 18, 2022 6:06 pm, edited 1 time in total.
 
mfrayyan
just joined
Topic Author
Posts: 12
Joined: Wed Mar 16, 2022 12:50 pm

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 5:37 pm

WOW
Special Thanks @rextended
Thanks to all

month not added in a comment

"00:AA:BB:CC:DD:EE 2022--18 16:25"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how can save mac address in a comment after login  [SOLVED]

Fri Mar 18, 2022 5:51 pm

RouerOS version? The script is for 6.4x, (probably) work for 7.x

Try this on terminal, must write correctly the date:
{
:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$($arrMonths->[:pick $curdatetime 0 3])-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")
:put $ldate
}

Without month name/value conversion:
{
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$[:pick $curdatetime 0 3]-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")
:put $ldate
}
do not personalize month names, must be on english,
if the output of the last is not
2022-mar-18 16:54
but something like
2022-Mar-18 16:54
or
2022-MAR-18 16:54
the array of month names must be changed accordingly.
Last edited by rextended on Fri Mar 18, 2022 6:10 pm, edited 2 times in total.
 
mfrayyan
just joined
Topic Author
Posts: 12
Joined: Wed Mar 16, 2022 12:50 pm

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 5:58 pm

yes all working now

after last edit print with this format :
2022-mar-18

thaaaaaaaaanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: how can save mac address in a comment after login

Fri Mar 18, 2022 6:05 pm

(Probably) fixed for 7.x month name/number conversion:
:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local curdatetime "$[/system clock get date] $[/system clock get time]"
:local ldate ("$[:pick $curdatetime 7 11]-$($arrMonths->[:pick $curdatetime 0 3])-$[:pick $curdatetime 4 6] $[:pick $curdatetime 12 14]:$[:pick $curdatetime 15 17]")

:local mac $"mac-address"
:log info "Prueba: $user $mac"
/ip hotspot user
:local comentario [get $user comment]
set $user comment="$mac $ldate - $comentario"

Who is online

Users browsing this forum: DanMos79 and 36 guests