The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘RouterOS’ Category

Some repositories with Mikrotik RouterOS Scripts (so no repos with API interfaces)

Posted by jpluimers on 2017/07/25

For my own reference:

–jeroen

Posted in Development, RouterOS, Scripting, Software Development | Leave a Comment »

Mikrotik RouterOS scripting: for loops are a bit of getting used to

Posted by jpluimers on 2017/07/18

Earlier, I wrote “:for loops are a strange beast so I will elaborate on those in a separate post.” so now is the time to do that.

The :for loop documentation is very dense:

Command Syntax Description
for :for <var> from=<int> to=<int> step=<int> do={ <commands> } execute commands over a given number of iterations

So a for loop has these elements:

  • from=
  • to=
  • step=
  • do=

Luckily, the old RouterOS 2.7 documentation on loops (which they’ve revamped after Router OS 2.7 removing many useful examples) has this:

:for – It has one unnamed argument, the name of the loop variable. from argument is the starting value for the loop counter, tovalue is the final value. This command counts loop variable up or down starting at from and ending with to, inclusive, and for each value it executes the do statement. It is possible to change the increment from the default 1 (or -1), by specifying the stepargument.

[admin@MikroTik] > :for i from=1 to=100 step=37  do={:put ($i . " - " . 1000/$i)}
1 - 1000
38 - 26
75 - 13
[admin@MikroTik] >

You might think that from= the start value, to= the finish value and the loop won’t execute when step= a positive value and from= larger than to=. Or that without a step= the loop will always iterate in ascending order.

Wrong! And wrong!

So it’s time for some…

:for loop examples

Read the rest of this entry »

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

Mikrotik RouterOS /ip firewall address-list timeout values sort-of documented

Posted by jpluimers on 2017/07/05

Thanks to ZeroByte answering at [Answered] Where are ip firewall address-list timeout values documented – MikroTik RouterOS [WayBack] which I edited a bit here:

I haven’t seen anything specific to the format of these time tokens, but the firewall add-to-address-list timeout is documented here:
http://wiki.mikrotik.com/wiki/Manual:IP … Properties…It seems to take the same format as any other similar duration-related input I’ve encountered:
  • a raw number is interpreted as seconds
You can specify a number as another duration with tokens:
  • s = seconds (default)
  • m = minutes
  • h = hours
  • d = days
  • w = weeks

A few aspects:

  • Tokens can combine be in any order
  • Whitespace is ignored

So these are all valid:

2s 2h 2w
1w2d3h4m5s
5s4m3h2d1w

  • Days and weeks just get added together. If you specify 1w8d, this is the same as 2w1d
  • The last value specified may be in h:m:s format or in h:m (omit seconds)
  • Interestingly, if you mix and match, they just get added:
    • “1d 2h 12:30” -> “1d 14:30:00”
  • Values larger than 536870911 seconds are stored and tracked but when displayed show as 0sec.
    (248 days, 13:13:55)
  • The maximum value is 4294967295 seconds (which is the maximum 32-bit value)
    This decodes to: 7101w3d6h28m15s as the largest value….
    (7101 weeks is ~136 years counting for leap years, by the way)

–jeroen

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

middelink/mikrotik-fwban: Use your Mikrotik firewall to do fail2ban like blocking of unwanted IPs. Written in Go

Posted by jpluimers on 2017/06/26

Interesting: middelink/mikrotik-fwban: Use your Mikrotik firewall to do fail2ban like blocking of unwanted IPs. Written in Go.

It might beat these (that just count SSH connections, not failed connection attempts):

Another alternative is to parse one of the logs:

Of course you should have this installed by default as part of your hardening process:

–jeroen

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

URLs for Mikrotik PCC load balancing

Posted by jpluimers on 2017/06/16

PCC load balancing saved my ass; here are some link I used:

–jeroen

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

Mikrotik firewall URLs

Posted by jpluimers on 2017/06/14

Some links that inspired me for various Mikrotik firewall rules:

–jeroen

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

URLs for Mikrotik scripts to block IP addresses after repetitive login failures

Posted by jpluimers on 2017/06/13

For my research list:

–jeroen

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »

Mikrotik scripting language: a list of questions I had linking to the forum messages having answers

Posted by jpluimers on 2017/06/08

The RouterOS scripting language you can use on Mikrotik device immediately shows it’s origin: the console.

  • It is a statement oriented language where statement separators can be both semicolons and new-lines.
  • You can use the \ at the end-of the line as line-continuation character effectively spreading statements over multiple lines.

As promised some links to questions I asked:

Some questions by others that were also extremely useful:

And a few observations:

  • Functions do not need to be global. The RouterOS Scripting Manual paragraph on functions shows an example with :global that works just as fine with :local
    :local myFunc do={:put "hello from function"} 
    $myFunc
     
    # output: 
    # hello from function
  • a

–jeroen

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | 1 Comment »

APC 7xxx models, DHCP Option 43 and Mikrotik DHCP servers

Posted by jpluimers on 2017/06/07

When switching my DHCP to a Mikrotik CCR1009, both the AP7920 and AP7921 failed to get IP addresses. The APC7921 would look bounce between waiting and offered states like this:

The cause is the need of DHCP Option 43 (Vendor Class Identifier) specified in RFC2132 – based on [WayBack] RFC 2131 – Dynamic Host Configuration Protocol and [WayBackRFC 1533 – DHCP Options and BOOTP Vendor Extensions – which I found first via these links:

Read the rest of this entry »

Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | 3 Comments »