Is it possible that I could use Dude or some other way to change some settings globally on our routerboards using Routerboard’s script?
We have many routerboards (200+) so i would like to use a script to change the whole lot at once.
Never used dude but you can telnet into Mikrotiks.
It’s easy to make scripts that automatically telnet into whatever and do what you want.
Attached is some code if you wanted to do this in php. Found it somewhere on this forum.
Here is how to use it:
<?php
include "telnet.php";
$ips = array("10.0.0.1", "10.0.0.2");
foreach ($ips as &$ip) {
routeros_connect("$ip", "username", "password");
routeros_cmd("/whatever command you want here");
fclose($fp);
}
?>
Wont let me add php files. Here is the contents:
<?php
/*
* RouterOS API
* Based on the code of SpectatorCN at http://forum.mikrotik.com/t/remote-control-of-traffic-shaping-over-ssh-telnet/29513/1
* Modified by Ali Damji
* Free to modify, distribute, do whatever.
*
*/
# Basic Functions
function routeros_connect($host, $username, $password) {
global $fp;
$header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x41).chr(0x4E).chr(0x53).chr(0x49).chr(0xFF).chr(0xF0);
$header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);
$fp=fsockopen($host,23);
fputs($fp,$header1);
usleep(125000);
fputs($fp,$header2);
usleep(125000);
write_to_telnet($fp,$username."+ct");
write_to_telnet($fp,$password);
read_from_telnet($fp);
}
function routeros_cmd($command) {
global $fp;
write_to_telnet($fp,"$command");
$rez = read_from_telnet($fp);
echo $rez;
}
# API Related
function ros_new_hotspot_user($username,$password,$email,$limit_kb,$limit_up) {
routeros_cmd("/ip hotspot user add name=$username password=$password email=$email limit-bytes-total=$limit_kb limit-uptime=$limit_up");
}
function ros_edit_hotspot_user($username,$password,$email,$limit_kb,$limit_up) {
routeros_cmd("/ip hotspot user set $username password=$password email=$email limit-bytes-total=$limit_kb limit-uptime=$limit_up");
}
function ros_disable_hotspot_user($username) {
routeros_cmd("/ip hotspot user disable $username");
}
function ros_enable_hotspot_user($username) {
routeros_cmd("/ip hotspot user enable $username");
}
function ros_hotspot_user_detail($username="") {
if ($username) routeros_cmd("/ip hotspot user print detail where name=$username");
if (!$username) routeros_cmd("/ip hotspot user print detail");
}
# Telnet Related
function write_to_telnet($fp, $text){
fputs($fp,$text."\r\n");
usleep(1250);
return true;
}
function read_from_telnet($fp){
$output = "";
$count = 0;
do{
$char =fread($fp, 1);
$output .= $char;
if($char==">") $count++;
if($count==1) break;
} while(1==1);
$output=preg_replace("/^.*?\n(.*)\n[^\n]*$/","$1",$output);
$o=explode("\n",$output);
for($i=1;$i<=count($o)-2;$i++) $op.=$o[$i]."\n";
return $op;
}
?>