Community discussions

MikroTik App

Search found 45 matches

by Vyrtu
Wed Nov 27, 2013 11:25 am
Forum: Scripting
Topic: Mikrotik script how to line break
Replies: 7
Views: 7395

Re: Mikrotik script how to line break

Hi again guys, i have a little problem with this script, this is the final code: :if ([/ping address=8.8.8.8 count=4]=4) do={ /file set miconexion.rsc contents ([/file get miconexion.rsc contents] . "\n" . [/system clock get date] . "\_" . [/system clock get time] ."\_ "...
by Vyrtu
Tue Nov 19, 2013 10:27 am
Forum: Scripting
Topic: Mikrotik script how to line break
Replies: 7
Views: 7395

Re: Mikrotik script how to line break

Nice it's working now, i put the final script, if somebody needs it: :if ([/ping address=8.8.8.8 count=25]=25) do={ /file set miconexion.txt contents ([/file get miconexion.txt contents] . "\n" . [/system clock get date] . "\_" . [/system clock get time] ."\_ ". "C...
by Vyrtu
Mon Nov 18, 2013 6:56 pm
Forum: Scripting
Topic: Mikrotik script how to line break
Replies: 7
Views: 7395

Re: Mikrotik script how to line break

You need to explicitly add to the contents, rather than replace it. Use the "/file" menu's "get" command to get the current contents. i.e. /file set miconexion.txt contents ([/file get miconexion.txt contents] . "\n" . [/system clock get date]) NICE! The script works, ...
by Vyrtu
Mon Nov 18, 2013 6:02 pm
Forum: Scripting
Topic: Mikrotik script how to line break
Replies: 7
Views: 7395

Mikrotik script how to line break

Hi, i have this script: :if ([/ping address=8.8.8.8 count=25]=25) do={ /file set miconexion.txt contents [/system clock get date] } else={/file set miconexion.txt contents [/system clock get date]} I need line break for each script run like that: nov/18/2013 nov/18/2013 nov/18/2013 nov/18/2013 And t...
by Vyrtu
Tue Nov 12, 2013 9:52 am
Forum: Scripting
Topic: Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Replies: 9
Views: 5626

Re: Print ppps from 2 Router Mikrotik in same code PEAR2 PH

If a router is turned off, there's nothing you can really do about it. You can specify a maximum number of seconds to wait for the connection to be established, but if you have too many routers, you can still exhaust PHP's 30 seconds timeout. You can do that at the 6th argument at "new RouterO...
by Vyrtu
Mon Nov 11, 2013 5:36 pm
Forum: Scripting
Topic: Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Replies: 9
Views: 5626

Re: Print ppps from 2 Router Mikrotik in same code PEAR2 PH

The errors are due to your script trying to connect to the router despite the failed connection. The best way to deal with this is to encapsulate your whole per-router script into a "try...catch" section, not just the "new RouterOS\Client" part. For each router i copy and paste ...
by Vyrtu
Mon Nov 11, 2013 12:04 pm
Forum: Scripting
Topic: Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Replies: 9
Views: 5626

Re: Print ppps from 2 Router Mikrotik in same code PEAR2 PH

Maybe with a ping before the request, and if it works, print the request, if not, it alerts me.. The problem is, how i can ping the router before the request? pd: Can I ignore the router with otherwise more simple? pd2: I have this now: <?php try { $client = new RouterOS\Client($ip, 'vito', 'vito');...
by Vyrtu
Mon Nov 11, 2013 9:47 am
Forum: Scripting
Topic: Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Replies: 9
Views: 5626

Re: Print ppps from 2 Router Mikrotik in same code PEAR2 PH

Hi again, i can connect 6 different routers mikrotik now..But i have a little problem. If i have 1 router turn off, the script doesnt work :S For each router i copy and paste this: <?php flush(); //Consulta al Primer cliente Mikrotik para sacar el listado ($client) //Imprime la informacion de Active...
by Vyrtu
Tue Nov 05, 2013 4:33 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Like I said, you're never sending the request... same as with your other recent topic . So: if (isset($_POST['act']))  {    foreach ($_POST['act'] as $act => $itemID)     {       if (in_array($act, array('remove')))             {                   $remove=new RouterOs\Request("/ppp/active/{$ac...
by Vyrtu
Tue Nov 05, 2013 9:56 am
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

in_array() checks against an array, not a string, so change if (in_array($act,'remove'))   to if (in_array($act, array('remove')))   To debug errors like this more quickly and easily, you may want to enable error display. Open up your php.ini file, look for "display_errors", and change th...
by Vyrtu
Mon Nov 04, 2013 4:47 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Well, you have the request here //Reiniciar PPP $remove=new RouterOs\Request("/ppp/active/remove"); $remove->setArgument('numbers', $itemID);   but you're never sending it. Also, you'll notice that as it stands, you're ALWAYS preparing this request, as opposed to only when the reset butto...
by Vyrtu
Mon Nov 04, 2013 1:45 pm
Forum: Scripting
Topic: System Identity API PEAR2
Replies: 1
Views: 1566

System Identity API PEAR2

Hi again :) I tried print a name of my mikrotik router and it returns nothing :S This is the code: <?php use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; $client = new RouterOS\Client('xx.xxx.xx.xxx', 'victor', 'xxxxx'); $cabecer...
by Vyrtu
Mon Nov 04, 2013 10:53 am
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Other question, how can i sort by name the table? Im trying with ksort but doesnt work :S ksort() sorts by key, and the response collection has the reply's number as a key (first received has 0, second received has 1, etc.), not the name, and it's already sorted... so while ksort() could work (as i...
by Vyrtu
Mon Oct 28, 2013 6:47 pm
Forum: Scripting
Topic: Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Replies: 9
Views: 5626

Re: Print ppps from 2 Router Mikrotik in same code PEAR2 PH

You have forgotten the toArray() call at $ppp1 and $ppp2. For the sake of performance, you might want to move away your requests into a variable that you then pass to all clients. Also, if there's a potentially growing list of routers (i.e. Client objects), consider placing them in an array instead...
by Vyrtu
Mon Oct 28, 2013 12:50 pm
Forum: Scripting
Topic: Print ppps from 2 Router Mikrotik in same code PEAR2 PHP
Replies: 9
Views: 5626

Print ppps from 2 Router Mikrotik in same code PEAR2 PHP

Hi, im here again, and now im trying print again the active connections and ppp's, but now, from 2 routers.. Here is the code: <?php use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; //Conexion a Mikrotik //IP MIKROTIK //Usuario /...
by Vyrtu
Mon Oct 28, 2013 12:27 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Im trying combine the 2 arrays in one(ppps, and active connection) and print it, but it doesnt work..
by Vyrtu
Mon Oct 28, 2013 10:32 am
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Its working, but now, i need print 2 mikrotik router in the same script. i add a new connection: $client = new RouterOS\Client('','admin','admin'); $client2 = new RouterOS\Client('xxx.xxx.xxx.xxx','admin','admin'); But now, i dont know how to continue the script..:S Other question, how can i sort by...
by Vyrtu
Fri Oct 25, 2013 12:36 pm
Forum: Scripting
Topic: Form to connect Mikrotik PEAR2 API PHP
Replies: 3
Views: 4653

Re: Form to connect Mikrotik PEAR2 API PHP

The single quotes mean the string is passed literally, rather than variables being interpolated. In other words, '$ip'  refers to a hostname called "$ip", which is obviously not a valid IP or domain name. Remove all apostrophes to pass the actual variable values, i.e. $client = new Router...
by Vyrtu
Fri Oct 25, 2013 12:22 pm
Forum: Scripting
Topic: Form to connect Mikrotik PEAR2 API PHP
Replies: 3
Views: 4653

Form to connect Mikrotik PEAR2 API PHP

hi guys, im here again :S Im trying create a form to connect a router mikrotik: <?php //ConectarAPI use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; //Formulario echo "<table><form action='' method='POST'> <tr> <td><input ty...
by Vyrtu
Thu Oct 24, 2013 4:43 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

P.D: I run the script again and.." Fatal error: Maximum execution time of 30 seconds exceeded Fuuuuu.... OK... remove the "unset" line. Apparently, freeing memory takes more time than a loop over your full list. (Note to self...) I haven't the unset line.. I just paste your last code...
by Vyrtu
Thu Oct 24, 2013 4:10 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Nice, its working, it takes about 20 seconds, but its ok. Now i need remove the active connections with the restart button. Something like /ppp/active/remove.. That's exactly the command - make such a request where you set the "numbers" argument to the ID of the active connection (the one...
by Vyrtu
Thu Oct 24, 2013 3:48 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Nice, its working, it takes about 20 seconds, but its ok.

Now i need remove the active connections with the restart button.

Something like /ppp/active/remove..
by Vyrtu
Wed Oct 23, 2013 6:20 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

If i dont compare the 'name's, it should be more fast, right? How is the code?
by Vyrtu
Wed Oct 23, 2013 6:10 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

After 5-10 minutes, the script finished but we have another error xD

"Fatal error: Maximum execution time of 5 seconds exceeded in phar://C:/wamp/www/PEAR2_Net_RouterOS-1.0.0b4.phar/PEAR2_Net_RouterOS-1.0.0b4/src/PEAR2/Net/Transmitter/NetworkStream.php on line 120"
by Vyrtu
Wed Oct 23, 2013 5:41 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Hmmm but, how i can increase the execution timeout? im using PEAR2_Net_RouterOS-1.0.0b4.phar
by Vyrtu
Wed Oct 23, 2013 5:10 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

The code print a bit of data (5 or 6 rows), but then i have this error:

"Fatal error: Maximum execution time of 30 seconds exceeded in phar://C:/wamp/www/PEAR2_Net_RouterOS-1.0.0b4.phar/PEAR2_Net_RouterOS-1.0.0b4/src/PEAR2/Net/RouterOS/Communicator.php on line 601"
by Vyrtu
Wed Oct 23, 2013 3:52 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

Re: print ppp active connections and interface list PEAR2 PH

Hmmm.. I need 'service' from /interface/pppoe-server instead 'service' from /ppp/active and name (interface/ppoe-server)= name(ppp/active), and i use 'if' like this: $interfaces = $client->sendSync(new RouterOS\Request('/interface/pppoe-server/print')); $ppps = $client->sendSync(new RouterOS\Request...
by Vyrtu
Wed Oct 23, 2013 1:50 pm
Forum: Scripting
Topic: print ppp active connections and interface list PEAR2 PHP
Replies: 27
Views: 29407

print ppp active connections and interface list PEAR2 PHP

Hi guys, im here again, with a new code: <?php use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; //IP MIKROTIK //Usuario //Password $client = new RouterOS\Client('xxx.xxx.xxx.xxx, 'admin', 'admin'); //Conexion a Mikrotik // Tabla ...
by Vyrtu
Wed Oct 23, 2013 10:44 am
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Re: Add new nat rule with PEAR2 PHP

Perfect, its working very well, thanks you so much again :)
by Vyrtu
Tue Oct 22, 2013 6:12 pm
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Re: Add new nat rule with PEAR2 PHP

Working, but we still have 2 problems, when i refresh after add, it add a new same rule, and i cant add new rule without protocol and ports. In winbox we can..
by Vyrtu
Tue Oct 22, 2013 5:10 pm
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Re: Add new nat rule with PEAR2 PHP

It adds the rule with 'accept' action, and when i refresh the page, it adds again the same rule..
by Vyrtu
Tue Oct 22, 2013 4:41 pm
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Re: Add new nat rule with PEAR2 PHP

The script looks good, but when i try add a new rule, doesnt work and alerts me ("failure: no chain specified")
by Vyrtu
Tue Oct 22, 2013 3:58 pm
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Re: Add new nat rule with PEAR2 PHP

Hmm.. doesnt work, i post the complete code: <?php use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; $client = new RouterOS\Client('192.168.150.161', 'admin', 'admin'); if (isset($_POST['act'])) { foreach ($_POST['act'] as $act =>...
by Vyrtu
Tue Oct 22, 2013 2:29 pm
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Re: Add new nat rule with PEAR2 PHP

I update the code, and its working, but i have another problem.
In radio buttons, when i choose src(chain srcnat), the action should be src-nat, and when i choose dst(chain dstnat), the action should be dst-nat
When i create a nat rule, it creates with action accept :S
by Vyrtu
Tue Oct 22, 2013 10:27 am
Forum: Scripting
Topic: Add new nat rule with PEAR2 PHP
Replies: 12
Views: 6289

Add new nat rule with PEAR2 PHP

Hi guys, im scripting a new code to add nat rules on mikrotik, and i need some help :S This is the code: <?php //Listas desplegables echo "</br>"; //Peticion a la API $addRequest = $client->sendSync(new RouterOS\Request('/ip/firewall/nat/add')); echo "<table align='center' border=2 bo...
by Vyrtu
Tue Oct 15, 2013 3:37 pm
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Re: Change or Delete NAT rules PEAR2 API PHP

It's working right now! Thanks for help :)
by Vyrtu
Tue Oct 15, 2013 9:54 am
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Re: Change or Delete NAT rules PEAR2 API PHP

That can't be right. You're breaking off the value attribute with the first apostrophe. But now i can remove the rules but dont update them.. EDIT: Yeah... Having apostrophes results in a DIFFERENT name. That's why you can't edit - the parameter name is again different. BTW, to remove, you don't ne...
by Vyrtu
Mon Oct 14, 2013 6:36 pm
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Re: Change or Delete NAT rules PEAR2 API PHP

That's odd. I have Firefox too, and with that last change in place, it works as expected in both it and IE10. Although note that there are no "OK" or "error" messages, so you may be left with the impression that nothing happened when you click the Modificar button. I solved, the...
by Vyrtu
Mon Oct 14, 2013 6:16 pm
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Re: Change or Delete NAT rules PEAR2 API PHP

I know, I changed to-addresses in ur first code, u had to-address too but its dont working.. Im using Firebug to see the code on the firefox and i have something wrong http://gyazo.com/20b4a734b8d73217ab46a46111426976 maybe something is wrong with the name.. :S and the button's name too: http://gyaz...
by Vyrtu
Mon Oct 14, 2013 5:51 pm
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Re: Change or Delete NAT rules PEAR2 API PHP

The buttons still dont working..When i modify the src address or ports or something in the table and then i click on Modify, the values refresh and come back to old values :S And the delete button neither working.. Im using the updated code right now Im so glad with ur help, thanks..I was working ha...
by Vyrtu
Mon Oct 14, 2013 4:29 pm
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Re: Change or Delete NAT rules PEAR2 API PHP

Thanks so much, i really need this code for my project..I changed some syntax errors but the rest its ok i have another problem, the buttons still dont working, i want in the input texts change my nat rules directly, but they still unchanged. i cant understand the action part of the code.. p.d Sorry...
by Vyrtu
Mon Oct 14, 2013 12:59 pm
Forum: Scripting
Topic: Enable and Disable Ethernet ports
Replies: 4
Views: 6976

Re: Enable and Disable Ethernet ports

My problem is solved. I post the final script. <?php require_once('api_mt_include2.php'); ?> <?php //////////////////////////////////////////////////////////////////// // ESTE EJEMPLO SE DESCARGO DE www.tech-nico.com /////////////////// // Creado por: Nicolas Daitsch. Guatrache. La Pampa ///////////...
by Vyrtu
Mon Oct 14, 2013 12:40 pm
Forum: Scripting
Topic: Change or Delete NAT rules PEAR2 API PHP
Replies: 12
Views: 3614

Change or Delete NAT rules PEAR2 API PHP

Hi guys, i need a script to modify or delete one of the nat rules's list. I have 2 buttons for each nat rule (modify, delete). The script is something like that: <?php use PEAR2\Net\RouterOS; // require_once 'pear2\src\PEAR2\Autoload.php'; require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar'; $client = ne...
by Vyrtu
Thu Oct 03, 2013 12:27 pm
Forum: Scripting
Topic: Enable and Disable Ethernet ports
Replies: 4
Views: 6976

Re: Enable and Disable Ethernet ports

Thanks, but i still having problems. It's my full code: <?php require_once('routeros_api.class.php'); ?> <?php $ipRouteros="192.168.2.1"; // tu RouterOS. $Username="adminapi"; // usuario API $pass="adminapi"; // contraseña del usuario API $api_puerto=8728; // Puerto API...
by Vyrtu
Thu Oct 03, 2013 12:00 pm
Forum: Scripting
Topic: Enable and Disable Ethernet ports
Replies: 4
Views: 6976

Enable and Disable Ethernet ports

Hi, i'm newbie with API's Mikrotik right now, and I need some help :S I need know how to enable and disable ethernet ports with api and php.. I was testing with these codes, but i cant fix them..Im so bad :( if ($API->connect($ipRouteros , $username , $pass, $api_puerto)) { { $API->write('/interface...