Community discussions

MikroTik App
 
kapi2454
newbie
Topic Author
Posts: 38
Joined: Mon Oct 09, 2017 2:54 pm

Script that get the Network Value

Thu Dec 30, 2021 3:14 pm

Hi people!! I need some help
I make an script to add rule in Firewall and NAT
It's simple and was Working fin until not :S
Firs Ask for the IP, External port, Internal port and Last a Name for rules

The problem is in the part that get the Network IP
# This line was working fine but now only print blank, i don't know why.
#I check and the name of interface "bridge" is fine, My temp Solution is comment that line and create a new one, puting the network ( :local LaRed 192.168.1.0 )
:local LaRed ([:pick [/ip address print as-value where interface="bridge"] 0]->"network")  
:local LaRed 192.168.1.0


I let here the entire script
:local input do={:put $1;:return}
:local LaIP [$input "IP"]
:local ElPuertoExterno [$input "Puerto Externo"]
:local ElPuertoInterno [$input "Puerto Interno"]
:local Comentario [$input "Nombre"]
#:local LaRed ([:pick [/ip address print as-value where interface="bridge"] 0]->"network")
:local LaRed 192.168.1.0

#:put "Login is [$LaIP] and password is [$LaIP]"
/ip firewall nat add action=dst-nat chain=dstnat comment="$Comentario_$ElPuertoExterno" dst-address-type=local dst-port=$ElPuertoExterno in-interface=all-ppp in-interface-list=!LAN protocol=tcp to-addresses=$LaIP to-ports=$ElPuertoInterno
/ip firewall nat add action=masquerade chain=srcnat dst-address="$LaRed/24" dst-port=$ElPuertoExterno out-interface=bridge protocol=tcp src-address="$LaRed/24"
/ip firewall nat add action=dst-nat chain=dstnat dst-address="!$LaRed/24" dst-address-type=local dst-port=$ElPuertoExterno protocol=tcp to-addresses=$LaIP to-ports=$ElPuertoInterno
/ip firewall nat add action=dst-nat chain=dstnat dst-address-type=local dst-port=$ElPuertoExterno in-interface=all-ppp in-interface-list=!LAN protocol=udp to-addresses=$LaIP to-ports=$ElPuertoInterno
/ip firewall nat add action=masquerade chain=srcnat dst-address="$LaRed/24" dst-port=$ElPuertoExterno out-interface=bridge protocol=udp src-address="$LaRed/24"
/ip firewall nat add action=dst-nat chain=dstnat dst-address="!$LaRed/24" dst-address-type=local dst-port=$ElPuertoExterno protocol=udp to-addresses=$LaIP to-ports=$ElPuertoInterno
/ip firewall filter add action=accept chain=forward dst-port=$ElPuertoExterno in-interface=all-ppp protocol=udp comment="$Comentario_$ElPuertoExterno" place-before=1 
/ip firewall filter add action=accept chain=forward dst-port=$ElPuertoExterno in-interface=all-ppp protocol=tcp place-before=2

Thank you!!
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script that get the Network Value

Fri Dec 31, 2021 6:28 pm

Dont use print in script:

try this:
:local LaRed [/ip address get [find  where interface="bridge"] network ]
If this does not get any result, post output of:
/ip address print

Who is online

Users browsing this forum: brunolabozzetta and 35 guests