Category Archives: scripts

Scriplet: Grabbing PPPoE IP Address

A quick scriptlet I whipped up for a friend tonight to allow them to retrieve an IP addess from a specific PPPoE interface.
Handy for updating DynDNS entries among other things.

:local wanip [/ip address get [/ip address find where interface=pppoe-wan] address];
:set wanip [:pick $wanip 0 ([:len $wanip]-3) ];
#whatever you want to do with said IP goes here
:put $wanip;

Obviously update pppoe-wan with your interface name 😉

Improved Netwatch-style script.

There have been a number of improved netwatch scripts listed on the mikrotik wiki in the past however many of these are hard to understand, broken or both.

I had a request from an associate to assist them finding a solution to fall over VPN traffic from one link to another in the event of an outage; in a network configuration where it wasn’t possible to use the local upstream router as an indication of the VPNs status, so I took the opportunity to revise a netwatch script based loosely on the one located here: http://wiki.mikrotik.com/wiki/Improved_Netwatch_II

My rewrite of this allows both the “up” and “down” scripts to be called from the same place (preferably a scheduler entry) and to be extra nice I’ve commented the whole script so you’re all welcome to modify as you see fit.

Continue reading Improved Netwatch-style script.

Adding automatic rate limits to user-manager accounts.

This has been mentioned and posted in a couple of places now however I’d like to post a copy here also in the event that anyone else has further suggestions on improvements for the script, or any further questions.

Although I don’t use it much myself, many Mikrotik users would be familiar with the “user-manager” package built by mikrotik as an “all-in-one” hotspot solution for small-medium installs.

Many of the functions in this are automated, however not the addition of per-account rate limits, which would normally be based on the package purchased. Instead most sites opt to use a preset speed value on a per router basis. An alternative option to this would be to put different users in different IP pools and setup a rate-limited queue tree based on that.

I was requested to build a script for use on the main user-manager mikrotik, that would allow accounts to be assigned a rate limit based on the package someone had purchased. Once set, this speed value remains the same.

Although this is sounds like quite a simple task, there’s a lot of work saved in having something like this automated, leaving you to get back to running day to day tasks rather than having to either limit all users to the same speed or worse, keep one eye on your user list to catch any newly created accounts!

With that I mind I wrote the following basic script to allow newly created accounts to be assigned a rate-limit based on the package they purchased.

You can modify the values to match your own options and rework this to your liking.

In this example you can see that, if I user purchased a $30 package (credit-price=30000) they would be assigned a rate limit of 512k/128k, whereas a $90 purchase would get a 2M/128k limit.

#Script to add rate limit's to newly created user-manager accounts.
#Written by Andrew Cox | Omega-00 | http://www.mikrotik-routeros.com

:local counter
:local check

#Loop through all users in user-manager
:foreach counter in=[/tool user-manager user find] do={

#Check to see if comment contains "RLA" (short for 'rate limit added'). If it doesn't, this account hasn't had a rate limit set yet.
#We only check the first 3 characters, this means you can continue to use the comment field for whatever you like so long as you leave the 'RLA' untouched (if present)
:set check [:pick [/tool user-manager user get $counter value=comment] 0 3]
:if ($check="RLA") do={

#Has RLA, rate limit is already set so ignore

} else={

#Doesn't have RLA Set rate-limit based on initial purchase pricing
:if ([/tool user-manager user get $counter credit-price] ="30000") do={/tool user-manager user set $counter rate-limit="512k/128k" comment="RLA"}
:if ([/tool user-manager user get $counter credit-price] ="60000") do={/tool user-manager user set $counter rate-limit="1M/128k" comment="RLA"}
:if ([/tool user-manager user get $counter credit-price] ="90000") do={/tool user-manager user set $counter rate-limit="2M/128k" comment="RLA"}
}  }

IPv6 and Mikrotik – Using 6to4

Please note this guide assumes some basic knowledge of IPv4 and IPv6 address space.

Many of you may know of the impending doom that surrounds the IPv4 network and lack of remaining IP ranges.

The question is, how many people are actually doing anything about it? Given the slow take up worldwide I thought it worthwhile I do a post here to explain how you can get IPv6 on your network now.
No support required from your upstream ISP and without having to send your traffic half way around the world to a Hurricane Electric tunnel (hopefully).

So, what is 6to4?

From: http://en.wikipedia.org/wiki/6to4

6to4 is an Internet transition mechanism for migrating from IPv4 to IPv6, a system that allows IPv6 packets to be transmitted over an IPv4 network (generally the IPv4 internet) without the need to configure explicit tunnels. Special relay servers are also in place that allow 6to4 networks to communicate with native IPv6 networks.
6to4 is especially relevant during the initial phases of deployment to full, native IPv6 connectivity, since IPv6 is not required on nodes between the host and the destination. However, it is intended only as transition mechanism and is not meant to be used permanently.

Continue reading IPv6 and Mikrotik – Using 6to4

Freebies in SA (or How to download IP address lists to a Mikrotik)

In the state of Australia I currently live in, there are 2 major ISP’s – Internode and Adam Internet.
Being a typical nerd and living with other typical nerds we of course have 2 ADSL connections, 1 to each of these providers which are shared out amongst the house.

Internet Cafe. Now where's my Mocha?

However each of these providers have what we call in Australia – “unmetered content” that is to say download traffic from these sources is not measured and removed from our download allowances (yes, we have limits on what we can download).

So anyway, I’ll make like a sharp stick and get to the point.

We wanted to make sure that free traffic from each ISP would always go via that ISP’s link to save us on downloads and each ISP offers a list of the free IP’s in a nice text format: Continue reading Freebies in SA (or How to download IP address lists to a Mikrotik)