Page 1 of 1
is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 10:24 am
by David1234
hello ,
does anyone know how can I make a script that count me the numbers of active users that using my hotspot?
every time I get a new entry (new person in start using the hotspot) the counter will get +1 , and in the end of the day I will get the number (and at the end of the day I will reset the counter)?
can it be done?
I have try to do this but without any luck so far
any help will be good ,
Thanks ,
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 12:31 pm
by ditonet
http://wiki.mikrotik.com/wiki/Manual:IP ... operties_2
Read about 'on-login' property.
Create script which increase (+1) global variable every run, and reset it at midnight.
HTH,
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 2:01 pm
by David1234
o.k. ,
this is very good
thank you!
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 2:05 pm
by mrz
No need for counter, etc.
/ip hotspot active print count-only
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 2:44 pm
by David1234
but this will print me the number at the current time and i will not see how many where before...
I need it for statistics.
that way I can say - yesterday were 100 people
and one week ago were 6000 people
.
if you have better way to do this - I will love to hear it
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 3:06 pm
by David1234
something is not working for me
I did what you advice me to do
and this is the script I wrote:
:global counter;
:set counter ($counter+1);
:log warning "numbers of users so far is $counter";
global systemTime [/system clock get time];
global systemDate [/system clock get date];
:global hotusers "The time is - $systemDate $systemTime
Numbers of hot spot users so far-$counter";
/file set [/file find name=hotusers.txt] contents=$hotusers;
but it won't count me
every time I get counter=1
in the hostpot on loggin script I wrote:
/system script run hotusers;(this is the name of the script above - I can see he is working ,I see the log..)
What did I miss?
Thanks ,
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 3:52 pm
by ditonet
This script works for me as expected:
:global counter;
:set counter ($counter + 1);
:log info "number of logged users: $counter";
Tested 5 minutes ago
HTH,
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 4:33 pm
by David1234
and you tried it in the hotspot- loggin script?
it's work for me also
but when I disconnect from the hotspot and after an hour connect again -
I still get the number 1
even when i delete the dhcp-server and hotspot host of my device
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 4:40 pm
by ditonet
and you tried it in the hotspot- loggin script?
Yes, this script works from hotspot 'on-login' and counts every new-connected user.
Regards,
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 5:03 pm
by mrz
What your script does is it counts total logins .. not logged in users at the time.
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 5:04 pm
by David1234
still something is wrong
I get log people=1 even that I have 2 people connected
look -
I want to know what did I do wrong?
thanks,
Re: is there a way to count hotspot users?
Posted: Wed Jun 20, 2012 5:39 pm
by ditonet
@mrz
What your script does is it counts total logins .. not logged in users at the time.
You are right, but David1234 asked for this.
@David1234
I don't know what's wrong with your script.
As I wrote earlier it works for me (RB450G, ROS 5.4)
Regards,
Re: is there a way to count hotspot users?
Posted: Thu Jun 21, 2012 10:03 am
by David1234
you can see at the log and in the counter more then 1?
what kind of hotspot did you config?
I have a free one and all the people who want to connect have the same user&pass
maybe this is the problem?
its count the names of the users and not the amount?
Re: is there a way to count hotspot users?
Posted: Thu Jun 21, 2012 8:28 pm
by ditonet
It is free hotspot, only two users (standard & vip).
Log shows number of user logins.
HS_logins.JPG
HTH,
Re: is there a way to count hotspot users?
Posted: Sun Jun 24, 2012 10:22 am
by David1234
still not good for me
all I get is : 1
this is what I have:
hotspot-user-profile-scripts-On login:
/system script run hotusers;
this is the hotusers script:
:global counter;
:set counter ($counter+1);
:log warning "numbers of users so far is $counter";
global systemTime [/system clock get time];
global systemDate [/system clock get date];
:global hotusers "The time is - $systemDate $systemTime
Numbers of hot spot users so far-$counter";
/file set [/file find name=hotusers.txt] contents=$hotusers;
and all I get in the Log file (and in the file ) is :
"The time is - jun/24/2012 09:50:52
Numbers of hot spot users so far-1"
and I can see that there is only 1 user at active (and I know that were 10 people connected since the lest time I did reset)
help?
Thank ,
Re: is there a way to count hotspot users?
Posted: Sun Jun 24, 2012 2:08 pm
by ditonet
Did you try my script without any modifications?
If not, try it, check how it work and next add new functionality (date, time, etc.)
HTH,
Re: is there a way to count hotspot users?
Posted: Sun Jun 24, 2012 4:22 pm
by David1234
did it
and again I only get - "1"
I connected to the HotSpot with 2 computers - I can see there is 2 active
but in the log I only see 1
this is the config of my Hotspot
/ip hotspot profile
set [ find default=yes ] login-by=http-pap
add dns-name=Free-Wifi hotspot-address=172.20.164.254 login-by=http-pap \
name=hsprof1
/ip hotspot
add address-pool=hs-pool-1 disabled=no interface=wlan1 name=hotspot1 profile=\
hsprof1
/ip hotspot user profile
set [ find default=yes ] address-pool=hs-pool-1 idle-timeout=5m \
keepalive-timeout=2m on-login=":global counter;\r\
\n:set counter (\$counter + 1);\r\
\n:log warning \"number of logged users: \$counter\";" session-timeout=1d \
shared-users=60
/ip hotspot user
add name=admin password=1234
add name=david
and in the login.html
is said that
<html><head><title>Free WIFI</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=320" /><script type="text/javascript">window.addEventListener('load', function() { setTimeout(scrollTo, 0, 0, 1); }, false);</script>
<body leftmargin="0" topmargin="0" marginwidth="0"><center><form name="login" action="http:login" method="post"><input type="hidden" name="dst" value="http://www.google.com" /><input type="hidden" name="popup" value="true" />
<INPUT CLASS="button" TYPE="image" src="img/top1.gif"/><center><a href="disclaimer.htm"><img src="img/but1.gif"></a></center><input type="hidden" style="width: 80px" name="username" type="text" value="david"/>
</form></center>
maybe now it will help more?
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 12:35 am
by ditonet
You simply misunderstood meaning of 'on-login' property.
Do not put your script here, only script name.
/ip hotspot user profile
add idle-timeout=5m keepalive-timeout=2m name=standard on-login=HSU_Count shared-users=200 status-autorefresh=1m transparent-proxy=no
Script must be defined in 'System/Scripts':
/system script
add name=HSU_Count policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source=":global counter;\r\
\n:set counter (\$counter + 1);\r\
\n:log info \"number of HS logins: \$counter\";"
HTH,
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 11:04 am
by David1234
I have done this with my script and also yours.
but again all I get is -
number of HS logins: 1
even when I have connected with 3 devices and I can see 3 on Active.
every time someone connecting I see on the log
number of HS logins: 1
what else may be wrong?
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 12:39 pm
by ditonet
Change your script to one line only:
:log info "New HotSpot user connected."
and observe log after user login to hotspot.
You should see this info in log.
HTH,
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 1:14 pm
by David1234
this I can see:
every time someone is connecting I can this line in the LOG.
the problem is that the counter isn't getting +1 or that he didn't save the last value and start from 0 every time - this is what I think
thanks ,
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 2:27 pm
by ditonet
Run terminal window from Winbox and run these commands line by line (only one line a time):
:global counter;
:set counter ($counter + 1);
:log info "number of logged users: $counter";
:set counter ($counter + 1);
:log info "number of logged users: $counter";
:set counter ($counter + 1);
:log info "number of logged users: $counter";
In Winbox 'System/Scripts' is tab 'Enviroment' where script's variables are shown.
Does 'counter' variable increments?
What log says?
What ROS version do you use?
HTH,
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 2:52 pm
by David1234
If I do this manually it's work ,and the counter grow.
I can see that
number of logged users: 4
I'm using 5.18 , but I have also try it on 5.7
and in the Environment tab (when the script is running normally , not now in the "manual mode")
I get nothing
don't see any "counter" or something else
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 3:06 pm
by ditonet
If variable is defined as 'global', shoud be visible in 'Enviroment' tab.
Maybe you missed something in your script (colons, semicolons, etc.), and your 'counter' is not global.
Check your script or copy-paste my working script and try again:
:global counter;
:set counter ($counter + 1);
:log info "number of HS logins: $counter";
HTH,
Re: is there a way to count hotspot users?
Posted: Mon Jun 25, 2012 3:49 pm
by David1234
bizarre!
Now it's working.
didn't change anything but the name of the script.
Thank you for the all your help!
Re: is there a way to count hotspot users?
Posted: Sat Aug 18, 2012 7:24 pm
by Etza
hi
can i put this number in login page ??
any help ???
Re: is there a way to count hotspot users?
Posted: Sun Aug 19, 2012 9:09 pm
by Etza
If variable is defined as 'global', shoud be visible in 'Enviroment' tab.
Maybe you missed something in your script (colons, semicolons, etc.), and your 'counter' is not global.
Check your script or copy-paste my working script and try again:
:global counter;
:set counter ($counter + 1);
:log info "number of HS logins: $counter";
HTH,
nice the script thx
but wyh after the reboot begeins from the start ??
any help for continius ????
Re: is there a way to count hotspot users?
Posted: Mon Aug 20, 2012 11:19 pm
by Etza
No need for counter, etc.
/ip hotspot active print count-only
can any help to put this in html login page ?????
Re: is there a way to count hotspot users?
Posted: Sun Apr 14, 2013 7:23 am
by akmjahangir
Re: is there a way to count hotspot users?
Posted: Fri May 17, 2013 11:20 am
by leroycorbid
:local numUsers 0;
:local time;
:set time [/system clock get time];
:foreach user in=[/ip hotspot active find] do={:set numUsers ($numUsers + 1)};
:log info "Number of users logged in at $time is $numUsers";
}
Run on a schedule
Re: is there a way to count hotspot users?
Posted: Thu Jul 04, 2013 10:35 pm
by thedoc
I still have a strange problem with counting hotspot users over time.
Made a script called hotspotcounter
/system script
add name=hotspotcounter policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
source=":global counter\r\
\n:set counter (\$counter + 1)\r\
\n:log info \"number of HS logins: \$counter\""
User profile with call to this script on login.
/ip hotspot user profile
add address-pool=hs-pool idle-timeout=none keepalive-timeout=10m name=\
"1024k 4096k burst" on-login=hotspotcounter rate-limit=\
"256k/1024k 512k/4096k 230k/900k 128/128 8 30k/75k" shared-users=1000 \
status-autorefresh=1m transparent-proxy=no
Script works if I run it inside the script window.
Global variable is visible and increased, and a message in log file.
When a hotspot user login counter is increased.
Problem is when I logout from winbox and later login again the counter is not working.
Only the message in the logfile number of HS login: 1
When i open the script window in winbox it is working again as long is a i am working in winbox.
What do I miss, why it is not working if I logout from winbox ?.
Re: is there a way to count hotspot users?
Posted: Fri Mar 10, 2023 12:43 pm
by eyesaka
Hello guys, please i need to know if it's possible, how to get hotspot user creating date and time with the mikrotik rest api. Thanks you.