Remove or Disable in API with PHP

Dear All.

<?php
//config
//Enter your mikrotik router IP, Username and password here

$serverip="192.168.1.1";
$username="admin";
$password="123456";
//***********************
require('api.php');
$address = $_SERVER['REMOTE_ADDR'];
$usercomment  = $_SERVER['QUERY_STRING'];
$API = new routeros_api();
$API->debug = false;
if ($API->connect($serverip, $username,$password)) {
	$API->comm("/ip/socks/access/add", array(
          "src-address" => "$address",
          "comment"  => "{$usercomment}",
          "action" => "allow",
));

I am using this API code for add IP in SOCKS.

How can change this code for Remove or Disable exmaple IP 3.3.3.3 ?

Make a print request with a query that matches the item you want to remove/disable/set. Part of the response will be the “.id” of that item. Pass that to the “numbers” argument of a new remove/disable/set command.

how can I edit this code with print request?

With my client, it would look like:

<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2/Net/RouterOS/Autoload.php';

$client = new Client('192.168.1.1', 'admin', '123456');

$id = $client->sendSync(
    new Request('/ip/socks/access/print .proplist=.id', null, Query::where('address', $_SERVER['REMOTE_ADDR']))
)->getArgument('.id');

$disableRequest = new Request('/ip/socks/access/disable');

$client->sendSync($disableRequest->setArgument('numbers', $id));
 

And with your current client… it would basically be two comm() calls.

tnx but This code does not work.
i upload PEAR2_Net_RouterOS in CPanel Host and use this code.
in this code i don’t need REMOTE_ADDR, and I just determine use a PHP variable $ for, set the ID.

example:
$delete_id=“3”;

You need an ID. Using a number won’t work. The “numbers” argument in MikroTik’s API, ironically enough, doesn’t accept numbers as its Winbox counterpart. You MUST use an ID, and you can get the correct ID with a print request, as in the example above.

If you want to disable a specifc IP (as opposed to $_SERVER[‘REMOTE_ADDR’]), you can hardcode the IP itself onto the query, i.e.

$id = $client->sendSync(
    new Request('/ip/socks/access/print .proplist=.id', null, Query::where('address', '3.3.3.3'))
)->getArgument('.id');