Skip to content
Advertisement

How to remove Mikrotik PHP Api firewall nat entry using find

I am trying to add and remove NAT entry using a single line php api code but unable to do it.

Terminal code Mikrotik:

/ip firewall nat remove [find comment=id9]

//Its working fine on terminal

I am trying writing bellow php api:

to Add:

$API->comm(“/ip/firewall/nat/addn=chain=dstnatn=src-address=103.19.131.3n=protocol=tcpn=action=dst-natn=comment=id9n=to-addresses=103.19.130.215n=to-ports=80”);

//Working fine

to remove:

$API->comm(“/ip/firewall/nat/remove/[findn=comment=id9]”);

 //Not working

Can anyone help me to solve it? Thanks in advance.

Advertisement

Answer

Its done. Bellow is the code:

//Remove Mikrotik NAT using PHP API

$API->write('/ip/firewall/nat/print', false);
$API->write('?comment=id9', false);
$API->write('=.proplist=.id');
$ARRAYS = $API->read();

$API->write('/ip/firewall/nat/remove', false);
$API->write('=.id=' . $ARRAYS[0]['.id']);
$READ = $API->read();

Thanks all for trying.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement