Roscon
Last updated
Last updated
The PHAR file is also an executable, that is an API protocol console. Running the PHAR file with any arguments will run the console. Also, installing PEAR2_Net_RouterOS with Pyrus, PEAR or Composer will give you an executable in your bin folder, called "roscon", which is that same console.
You can use the console to quickly test for connectivity, login and API protocol related issues, making sure that certain errors are ultimately due to RouterOS and/or configuration, and not due to a bug in PEAR2_Net_RouterOS or your code.
(Strictly speaking, the console is more of a REPL application)
You can get a list of all command line options and arguments by either running the "roscon" executable without arguments, or running the PHAR with the "--help" option.
Here's a more nicely formatted version of what you'd see:
Connecting to RouterOS at 192.168.88.1 without credentials over the default API port (8728):
This mode allows you to diagnose issues occurring prior or during the login procedure itself or with commands that may otherwise be issued anonymously.
Same as above, but with username "admin" and no password:
Same as above, but with "password" being used as the password for "admin" (as all other examples in this wiki):
Same as above, but on port 443 instead of port 8728:
As mentioned in the beginning, the console is a REPL application, and as such, it follows that flow. In other words, after a connection is established (and perhaps after you're logged in):
You write an API protocol word.
At some point (defined by the --command-mode
option), no more reading is done, and all collected input is sent to RouterOS. The console goes back to step 1 if that point is not yet reached.
The console waits for data up to the time defined by --timeout
, and once a word is received or the time is up, it prints on screen what's been received.
Up to a certain point (defined by the --reply-mode
option), the console keeps repeating step 3.
After receiving is done, if the connection is still alive, things go back to step 1. Otherwise, connection is terminated, and the console exits.
Using the command line
Here's the output from "/system/package/print" on RouterOS 6.19, followed by a "/quit" after its completion:
All rows with "\" (mode "SEND") are the points where the console reads from STDIN (i.e. your input). If you're saving the output to a file (as was done to generate this example), you can see what was written as input in the "SENT" rows just below. Those, as well as the length, are only visible in verbose mode, which you can enable with the "-v" option, as shown above. Non-verbose mode looks more like the examples from the API protocol specification where no length is shown, and direction is only indicated with color (as is done here, if you have the needed requirements, described above in the --colors
option).
Option
Short option
Default
Description
-p
Port to connect to. Default is either 8728 or 8729, depending on whether an encryption is specified.
Time in seconds to wait for the connection to be estabilished. If "--timeout" is specified, its value will be used when this option is not specified. Defaults to PHP's default_socket_timeout ini option.
Encryption to use, if at all. Currently, RouterOS supports only "TLS". (Default: "")
Optional path to a file or folder to use for certification authority, when using encryption. Ignored when not using encryption or using ADH cipher.
-t
Time in seconds to wait when receiving. If this time passes without data awaiting, control is passed back for further input. (Default: 3)
-v
Turn on verbose output.
auto
Choose whether to color output (requires PEAR2_Console_Color). Possible values: "auto" - color is always enabled, except on Windows, where ANSICON must be installed (detected via the ANSICON_VER environment variable). "yes" - force colored output. "no" - force no coloring of output. (Default: "auto")
-w
80
Width of console screen. Used in verbose mode to wrap output in this length. (Default: 80)
s
Mode to send commands in. Can be one of: "w" - send every word as soon as it is entered "s" - wait for a sentence to be formed, and send all its words then "e" - wait for an empty sentence, and send all previous sentences then. You can send an empty sentence by sending two consecutive empty words. (Default: "s")
s
Mode to get replies in. Can be one of: "w" - after every send, try to get a word "s" - after every send, try to get a sentence "e" - after every send, try to get all sentences until a timeout. (Default: "s")
-m
Turn on multiline mode. Without this mode, every line of input is considered a word. With it, every line is a line within the word, and the end of the word is marked instead by an "end of text" character as the only character on a line. To write out such a character, you can use ALT+Numpad3. If you want to write this character as part of the word, you can write two such characters on a line.
Name
Required
Description
hostname
Yes
Hostname of the RouterOS to connect to.
username
No
Username to log in with. If left empty, no login will be performed.
password
No
Password to log in with.