Community discussions

MikroTik App
 
manjay
just joined
Topic Author
Posts: 4
Joined: Thu May 09, 2019 8:35 pm

Script to compare dst-address variable to a preset address

Mon Oct 05, 2020 11:22 pm

Good Day

Please can the enlightened ones of the mikrotik world assist me with the following

I am trying to implement a scheduled script that will look for a certain dst-address:port in firewall connections and then simply send a log message if the dst-address:port i want is present or not.
Currently i have got something like this

:if (/ip firewall connection get [/ip firewall connection find src-address="192.168.1.20:5060"] dst-address=xx.xx.xx.xx:5060) do={/log info sipup} else={/log onfo sipdown}

However i think this is farrr off currently.
i have also successfully generated a script to help add the actual dst-address from firewall-connections to a variable

/global 5060 [/ip firewall connection get [/ip firewall connection find src-address="192.168.1.20:5060"] dst-address]

maybe with the saved variable the dst-address can be compared to a preset ipaddress.
This is to monitor sip traffic on a scheduled basis.

Any feed back or assistance will be much appreciated
 
Lelik200
just joined
Posts: 22
Joined: Fri Jul 24, 2020 1:48 pm

Re: Script to compare dst-address variable to a preset address

Mon Oct 19, 2020 7:55 am

Hello!
If I understood you correctly, then:
:local ArrToFind {
  "8.8.8.8:443";
  "8.8.8.8:53";
  "1.1.1.1:111"}
:local I
:foreach I in=$ArrToFind do={
  :put ($I . " - " . [:len [/ip firewall connection find where dst-address=$I]])
}

result:
8.8.8.8:443 - 2
8.8.8.8:53 - 0
1.1.1.1:111 - 0

Who is online

Users browsing this forum: Lelik200, vibhupandey and 26 guests