Scripting Ideas ??

Hi everybody
I want to measure my abilities with mikrotik scripting language (only mikrotik scripting no API)
so if anyone has an idea for script i ll try to solve it for him

Very nice offer. Maybe twice a day someone requires a script here on the forum. You can just post an answer to those requests…

Here goes one…

I have 2 3g/4g Ethernet routers that i am using as Wan1 and Wan2 links.
What I am trying to do is the following:

all traffic should go out Wan1 until I hit my data limit. The Telco gives me full speed of 4-20G until I hit my limit then throttles me to 32K. So the switch mechanism could be use Wan1 until the speed drops (I think very difficult but does not rely on data counters) or check data counters then disable Wan1 and use Wan2 (default backup routes i think).
Reset data counters on interfaces on specific day of the month.

I would appreciate any help, hints ETC…


Thanks

what you want is exactly here , (the traffic monitor tool) :
http://wiki.mikrotik.com/wiki/Manual:Tools/Traffic_Monitor
for resetting-counters , you need to put this in a scheduler that is repeated monthly …
/interface ethernet reset-counters “name of your interface, example:ether1”
sometimes this not , so you need to put a scheduler to reboot the RB each month
/system reboot

A script to maintain a list of static DNS entries based on host names found in DHCP leases. Allow the Mikrotik admin to specify the suffix, so a hostname of PC100 gets set as PC100.mycompany.local in the static DNS.

I dont get the full idea, but i think this is what you are looking for : (just copy and past in the new terminal)
/system script add name=Host_Name_DNS owner=admin policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive source=“#By Sin
an AlChalabi\r
\n#12-3-2016\r
\n#Static DNS enrty for DHCP leases \r
\n#Edit the suffix below\r
\n:local suffix ".mycompany.local"\r
\n:foreach i in [/ip dhcp-server lease find] do={\r
\n:local hname [/ip dhcp-server lease get value-name=host-name $i]\r
\n:local hadd [ip dhcp-server lease get value-name=address $i]\r
\n:local dnsname ("$hname"."$suffix")\r
\n/ip dns static add name=$dnsname address=$hadd ttl=1d\r
\n}”

Hi Sinan, I looked at traffic monitor but I get the impresion that its for bandwith not for data passed through the interface.. Am I wrong???



it is for the rate of your data , so you can put the rate 32kbps if it is below it , then disable this interface …

Hey Sinan,
Here’s one for you I’ve been struggling with. I’m wanting to loop through all wifi channels in the 2.4GHz with a set delay between the channel changes.

For example: Frequency 2412, wait 30 seconds, change to 2417, wait 30 seconds, change to 2422, wait 30 seconds, etc… and have it continually loop until powered off.

Help with this would be greatly appreciated. Thank you.

David

See below!

I’m curious though, what’s the purpose of changing the frequency so frequently?

{
do {

:local WirelessLanName “wlan1”;

:local wlan [/interface wireless get [find name=$WirelessLanName]];

:local freq ($wlan->“frequency”);

:if ($freq = 2462) do={set $freq 2412} else={set $freq ($freq + 5)};

:set ($wlan->“frequency”) $freq;

/interface wireless set [find id=($wlan->“id”)] frequency=$freq

delay 30s;

} while=(0=0);

}

thanx for answering instead of me.
if wanted to change the interval i suggest to put it in scheduler with the desired interval instead of using the delay function that will be easier to edit

Looks like it will work, thank you.
I just wanted something automated to hop through the channels for signal strengths at each channel. Primarily to see if there were any significant advantages for one channel versus another other than just looking at an app of my phone. Thanks again.

hi i need script for ( hotspot >user profile > script > on login & on logout)
that add nat masquerade (ip firewall nat add action=masquerade chain=srcnat src-address=userIP)
and remote it after user logout
i use 2 ip pool for hotspot first dhcp assign ip to user when he connect to wlan , second hotspot assign ip to logged in users form another ip pool
i need nat for second ip pool

Hi Sinan,

can you help me for some scripting ?

To forum jest w języku angielskim zatem proszę go używać :slight_smile:

This forum is in English language so please use it. :slight_smile:

Sory , I changed it

What are you looking for?

some script will take ddosed ip’s from /ip firewall address-list and will add this to black hole like this /ip route add bgp-communities=1111:333 comment=ddosed distance=1 dst-address=“$id/32” type=blackhole i would like to run this every 5min and it will check again if ip removed from ddosed it will automatically remove it from black hole also.

Thanks.

So you have the address-list already? Then why don’t you just make a firewall rule to drop all packets from that address-list? Why does it have to be a route?

/ip firewall filter
add action=drop chain=forward src-address-list=test comment=ddosed 
add action=drop chain=input src-address-list=test comment=ddosed 

but I would like to sent them to upstream provider blackhole :slight_smile: