need help for php script to edit mac in arp

Router OS version: 4.17

First of all I am a newbie. I have tried to edit mac address of my arp table using a php script. The code of the php script is as follows:

<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = true;

if ($API->connect('223.27.115.4', 'admin', '')) {

   $API->write('/ip/arp/edit', false);         
   $API->write("=.id=*2",false);               
   $API->write('=value-name=mac-address',true);
   $API->write('=mac-address=13.13.13.13',true);
   
   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);

   print_r($ARRAY);

	
   $API->disconnect();

}
?>

This return the following message.

Connection attempt #1 to 223.27.115.4:8728… <<< [6] /login >>> [5/5 bytes read. >>> [5, 39] !done >>> [37/37 bytes read. >>> [37, 1] =ret=dfb945995c2ab92b6c4409f132609554 <<< [6] /login <<< [11] =name=admin <<< [44] =response=0061bff1e3a42a07d1323460ddd81f9534 >>> [5/5 bytes read. >>> [5, 1] !done Connected… <<< [12] /ip/arp/edit <<< [7] =.id=*2 <<< [23] =value-name=mac-address <<< [24] =mac-address=13.13.13.13 >>> [5/5 bytes read. >>> [5, 64] !trap >>> [9/9 bytes read. >>> [9, 54] =message= >>> [5/5 bytes read. >>> [5, 47] !done >>> [5/5 bytes read. >>> [5, 40] !trap >>> [31/31 bytes read. >>> [31, 8] =message=no such command prefix >>> [5/5 bytes read. >>> [5, 1] !done Array ( [!trap] => Array ( [0] => Array ( [message] => ) [1] => Array ( [message] => no such command prefix ) ) ) Disconnected…

Please help. I need it urgent. Please fix my php script.

Thank you.

In the API, you need to use “set”, not “edit”.

I think you should also use “numbers” to specify the ID that you’ll edit, not “.id”. “.id” is to be specified only if you wish to change the ID.

$API->write(‘/ip/arp/edit’, false);
$API->write(“=.id=*2”,false);
$API->write(‘=value-name=mac-address’,true);
$API->write(‘=mac-address=13.13.13.13’,true);

>

'/ip/arp/edit' is not a valid api command; the mac-address above is not a mac address; the forth line never applies anyway as the third line has 'true' which terminates the command.

Try this:

```text
   $API->write('/ip/arp/set', false);         
   $API->write('=.id=*2',false);               
   $API->write('=mac-address=13:13:13:13:13:13',true);

Thanks both of you. I understand my fault. Thank you again.