Community discussions

MikroTik App
 
bartjoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Apr 09, 2013 5:56 pm

Script

Fri Dec 13, 2013 10:34 am

Hello, iam searching for a script who disabled the WLAN connection when there is no reply on a ping, when there is a reply, he must turn on the WLAN connection.
who have one like this or could make it for me?

I have some hotspots and i dont want a SSID sending out when there is no internet connection availilble.
greetz
Bart
 
nerdtron
Member Candidate
Member Candidate
Posts: 123
Joined: Sat Nov 30, 2013 7:49 am

Re: Script

Fri Dec 13, 2013 11:31 am

Add a comment to the wlan1 as "WIFI"
##netwatch script 1,check if internet on port 1 is down
## This will ping 8.8.8.8 on the internet, if it doesn't respond in 15 consecutive tries and if wifi is up, wlan1 interface will be disabled.
 :local i 0; {:do {:set i ($i + 1)} while (($i < 15) && ([/ping 8.8.8.8 interval=3 count=1]=0))};
       :if ($i=15 && [/interface wireless get [find comment="WIFI"] disabled]=no) do={:log info "Internet is down, shutdown wireless"; 
         /interface wireless set wlan1 disabled=yes}
##netwatch script 2, check if internet on port 1 is up
## This will ping 8.8.8.8 on the internet, if it replies for 10 tries and if wifi is previously disabled, it will be enabled.
 :local i 0; {:do {:set i ($i + 1)} while (($i < 10) && ([/ping 8.8.8.8 interval=3 count=1]=1))}; 
      :if ($i=10 && [/interface wireless get [find comment="WIFI"] disabled]=yes) do={:log info "Internet is up, turn on the wifi"; 
      /interface wireless set wlan1 disabled=no}
Add the two separate scripts on /System> Scripts.
Then add them on the scheduler /System> Scheduler Click the + sign and add the on event command like
/system script run script1
/system script run script2
Set them to run every 5 minutes if you like.
 
bartjoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Apr 09, 2013 5:56 pm

Re: Script

Fri Dec 13, 2013 11:57 am

Wow! great! tnx.. i will try it!

Who is online

Users browsing this forum: vitaliy91 and 104 guests