is it possible to remove dns server entry in ip>dns>servers via terminal without using the /ip dns edit servers ?
actually, I need to be able to remove them via API as simple as adding servers… sadly… with edit mode, it looks so highly difficult to code the program…
You can use the “set” command (either in API or in terminal/script).
But since the servers are a single comma separated list, you need to set the whole list. You can’t just remove a particular item.
With the API, it’s not so difficult to do. Most languages have means to split a string based on a character. In PHP for example, using the client from my signature:
$util->setMenu('/ip dns');
$servers = explode(',', $util->get(null, 'servers'));
//remove the 1st server
unset($servers[0]);
$util->set(null, array('servers' => implode(',', $servers)));
It’s a little more difficult in scripting, since there’s no equivalent of explode() or implode(), but it is doable still.
I’ve succeeded splitting with comma delimiter then I put them into an array to be viewed in listview rows…
but, when I tried to find terminal command for modify the records, I was shocked that edit mode is the only way since in edit mode users need to press Ctrl+O to save it… so, how can I send the Ctrl+O to the router via API?
fyi…
I’m using vb.net with tik4net libs by danikf… there might be another way you know with dani’s library…
Again: Use “set” instead of “edit”. The “set” command IS available over API.
The equivalent in terminal is “/ip dns set server=$servers” where $servers is the whole comma separated list (which you’ve previously processed, so that it doesn’t include the server you want removed).
With that client, using its “ADO.NET like” interface, it should be something like:
Dim cmd = connection.CreateCommand(
"/ip/dns/set",
connection.CreateParameter("servers", servers)
)
cmd.ExecuteNonQuery()
(where again, the “servers” variable is a string containing all DNS servers, after you’ve processed them)