Running Winbox from a URL

Ever wanted to have a button on a web page that would open up Winbox to a certain router/switch in your network?

Have you realized that Mikrotik’s Winbox, while it can be invoked from a command line, Mikrotik can’t be bothered to add in support for URLs?

Well, that’s where I was last week, we were implementing a network documentation system (Netbox) and realized we really wanted to have a button that would launch Winbox. We already had the Username and Password as well as the loopback/management interface for most of our equipment. Why not have a button that would do the hard work for us?

So I pulled out my favorite scripting language PowerShell and started messing around to see what I could do. Fun fact, PowerShell scripts, while great at calling Winbox, can’t be set as the destinations for URLs to open. So I needed some way to convert my PowerShell into a .exe (Because learning how to do the same thing in another language would just be foolish.)

The first step is registering the Protocol URL with windows: I chose “winbox:\\\\” because it seemed simple enough and highly unlikely that other applications were already using it. Of course, you can’t register a PowerShell script to handle URLs, security concerns or something. So I found a handy dandy PowerShell to .exe script and GUI at I just wrote a script that printed out what was sent to it at first so I could figure out how Firefox and Chrome were sending their data.

Next up is the stupitidty of web browsers, Firefox sends the whole URL to the invoked program “winbox:\\\\”, while Chrome changes the “\\\\”s to %5 something something. Windows on the other hand just sends the data without the “winbox:\\\\”. So you will have to use logic in your program to interpret the data sent by the browsers into 3 different variables. Address/Hostname, Username and Password.

You will need to edit your registry to inform it about opening winbox:// URLs. Which is pretty straightforward. I will try to add in a Registry key you can download and run. But Everything will be in HKEY_Classes_Root where you add in a key for winbox and underneath that a few levels put a key that points to winboxcommand.

Note, in my solution I utilize “?”s to separate values, address, username and password. If you don’t want to be storing passwords or you are ok with entering usernames and passwords for each of your devices you can save yourself some time. If you use my code though, it might be imprudent to use “?”s for your usernames especially, and possibly for your passwords.

If your using Radius your life gets a lot simpler there as well, then you just have your Username and a Secret unique to your account instead of a unique password per device. Though I have not implemented that yet and I need to play with that a bit.

This is still a very duct tape solution, but it works alright and if you just want something that’s simple, here’s at least some pointers for you.

Making Things Work Network Design