Community discussions

MikroTik App
 
calvinkli
just joined
Topic Author
Posts: 7
Joined: Mon Feb 06, 2017 9:27 am

ip firewall address-list and get hotspot active user info [SOLVED]

Wed Sep 16, 2020 8:31 am

hi all this is simple script which found at mikrotik forum , but what im trying is to get more information result .
:local CHID "xxxxx";
:local BotID "xxxxxx";

:local Total [/ip firewall address-list print count-only];

:if ($Total=0) do {
:return true
} else {
:local output
:foreach activeIndex in=[/ip firewall address-list find] do={
:local activeAddress ("".[/ip firewall address-list get value-name="address" $activeIndex]."%0A")
:set output ($output.$activeAddress."%0A")
}
}
/tool fetch url="https://api.telegram.org/bot$BotID/sendmessage\?chat_id=$CHID&text=$output Total Active Address List: $Total";
:delay 10
/file remove [/file find type=""];
with above result finding
im try to get the $activeAddress and locate the /ip hotspot active user
:foreach activeIndex2 in=[/ip hotspot active find where address=$activeAddress] do={
:local activeUser ("*Username*: ".[/ip hotspot active get value-name="user" $activeIndex2]."%0A")
:set output2 ($output2.$activeUser."%0A")
}
this is the result i need,
$activeAddress (eg 10.0.0.1)
$activeUser (abcd)

the first script no issue , please help on the 2nd code, thank you.
Last edited by calvinkli on Thu Sep 17, 2020 8:29 pm, edited 3 times in total.
 
calvinkli
just joined
Topic Author
Posts: 7
Joined: Mon Feb 06, 2017 9:27 am

Re: ip firewall address-list and get hotspot active user info

Thu Sep 17, 2020 6:21 am

:local CHID "xxxx";
:local BotID "xxxx";

:local output
:foreach activeIndex in=[/ip firewall address-list find] do={
:local activeAddress [/ip firewall address-list get $activeIndex address]

:foreach active2 in=[/ip hotspot active find address=$activeAddress] do={
:local activeUser [/ip hotspot active get $active2 user ]

:set output ($output.$activeAddress.$activeUser."%0A")
}

/tool fetch url="https://api.telegram.org/bot$BotID/sendmessage\?chat_id=$CHID&text=$output";
:delay 10
/file remove [/file find type=""];

hi , this is another update test, but still fail
 
calvinkli
just joined
Topic Author
Posts: 7
Joined: Mon Feb 06, 2017 9:27 am

Re: ip firewall address-list and get hotspot active user info

Thu Sep 17, 2020 8:27 pm

:local output
:foreach activeIndex in=[/ip firewall address-list find] do={
:local activeAddress [/ip firewall address-list get $activeIndex address]
:set output ($output.$activeAddress."%0A")
:foreach active2 in=[/ip hotspot active find address=$activeAddress] do={
:local activeUser [/ip hotspot active get $active2 user]
:set output ($output.$activeUser."%0A")

after many test, manage to get the result finally. [SOLVED].

Who is online

Users browsing this forum: peri and 16 guests