K
K
keyrus_ua2020-06-22 12:49:46
Mikrotik
keyrus_ua, 2020-06-22 12:49:46

How to set up Mikrotik so that Telegram receives messages when an IP address is added to the address list?

There is a rule in the firewall, adding an address to the address list by ping with a certain packet length

/ip firewall filter add action=add-src-to-address-list address-list=test address-list-timeout=5h chain=input packet-size =1000 protocol=icmp in-interface=ether1

there is a script that sends a message to telegram
/tool ​​fetch url=" https://api.telegram.org/bot***********:****** ******... "

Task: how to do something so that when adding an address to the address sheet, a message comes that a new address has been added, or, ideally, that the address itself comes in the cart

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
poisons, 2020-06-23
@poisons

There will be no code. But the logic should be like this.
1. By the rule on the firewall, add the ip address to the list, add the "new" comment to it. You already have it.
2. Once a minute, the scheduler runs through the address of the sheet in search of records with the comment "new", for these records we send a notification to the cart, remove the comment from them / replace the comment with "old". And this is what needs to be written. You can pull more often if it makes sense.
In order to run to the address of the sheet, the construction :foreach + find + do will help you.

K
kertiskz, 2020-07-30
@kertiskz

Perhaps crooked, I'm doing this for the second day.

:local counter;
:foreach counter in= [/ip firewall address-list find list=ХХХХХХ] do={
    :local ip [/ip firewall address-list get $counter address];
tool fetch url="https://api.telegram.org/botХХХХХХХХХХХХХХХ/sendMessage?chat_id=ХХХХХХХХХХХ&text=$ip+ХХХХХ" keep-result=no};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question