Community discussions

MikroTik App
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

is there a way to count hotspot users?

Wed Jun 20, 2012 10:24 am

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 ,
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 12:31 pm

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 2:01 pm

o.k. ,
this is very good
thank you!
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7169
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 2:05 pm

No need for counter, etc.
/ip hotspot active print count-only
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 2:44 pm

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
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 3:06 pm

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 ,
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 3:52 pm

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 4:33 pm

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
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 4:40 pm

and you tried it in the hotspot- loggin script?
Yes, this script works from hotspot 'on-login' and counts every new-connected user.

Regards,
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7169
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 5:03 pm

What your script does is it counts total logins .. not logged in users at the time.
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 5:04 pm

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,
You do not have the required permissions to view the files attached to this post.
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Wed Jun 20, 2012 5:39 pm

@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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Thu Jun 21, 2012 10:03 am

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?
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Thu Jun 21, 2012 8:28 pm

It is free hotspot, only two users (standard & vip).
Log shows number of user logins.
HS_logins.JPG
HTH,
You do not have the required permissions to view the files attached to this post.
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Sun Jun 24, 2012 10:22 am

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 ,
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Sun Jun 24, 2012 2:08 pm

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Sun Jun 24, 2012 4:22 pm

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?
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 12:35 am

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 11:04 am

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?
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 12:39 pm

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 1:14 pm

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 ,
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 2:27 pm

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 2:52 pm

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
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 3:06 pm

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,
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1424
Joined: Sun Sep 18, 2011 7:00 pm

Re: is there a way to count hotspot users?

Mon Jun 25, 2012 3:49 pm

bizarre!
Now it's working.
didn't change anything but the name of the script.

Thank you for the all your help!
 
Etza
newbie
Posts: 46
Joined: Tue May 31, 2011 10:33 pm

Re: is there a way to count hotspot users?

Sat Aug 18, 2012 7:24 pm

hi
can i put this number in login page ??

any help ???
 
Etza
newbie
Posts: 46
Joined: Tue May 31, 2011 10:33 pm

Re: is there a way to count hotspot users?

Sun Aug 19, 2012 9:09 pm

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 ????
 
Etza
newbie
Posts: 46
Joined: Tue May 31, 2011 10:33 pm

Re: is there a way to count hotspot users?

Mon Aug 20, 2012 11:19 pm

No need for counter, etc.
/ip hotspot active print count-only
can any help to put this in html login page ?????
 
akmjahangir
newbie
Posts: 48
Joined: Sun Aug 10, 2008 8:27 pm
Location: Dhaka, Bangladesh
Contact:

Re: is there a way to count hotspot users?

Sun Apr 14, 2013 7:23 am

 
leroycorbid
just joined
Posts: 8
Joined: Thu Mar 28, 2013 12:42 am

Re: is there a way to count hotspot users?

Fri May 17, 2013 11:20 am

: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
 
User avatar
thedoc
just joined
Posts: 12
Joined: Fri Feb 06, 2009 12:51 pm

Re: is there a way to count hotspot users?

Thu Jul 04, 2013 10:35 pm

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 ?.
 
eyesaka
just joined
Posts: 2
Joined: Wed Jan 18, 2023 2:44 pm

Re: is there a way to count hotspot users?

Fri Mar 10, 2023 12:43 pm

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.

Who is online

Users browsing this forum: No registered users and 10 guests