Community discussions

MikroTik App
 
planetcaravan
Member Candidate
Member Candidate
Topic Author
Posts: 267
Joined: Tue Aug 25, 2009 5:33 pm

[SOLVED] How to know if router has a wlan interface

Sat Oct 20, 2012 12:38 pm

Hi there,

I want to write a script like this
if ($myRouterHasWlan = true) {run this}
else {run that}
how can I make it in RouterOS?
Last edited by planetcaravan on Sat Oct 20, 2012 10:01 pm, edited 1 time in total.
 
readycool
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Mon Jan 31, 2011 11:25 pm

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 6:13 pm

Try this:
# Check that if we're using a wireless LAN
:if ($usewlan = "yes") do={
or this:
# Check that the WAN interface exists
:if ([/interface find name=$waninterface] = "") do={
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 7:03 pm

{
local wlan [len [interface wireless find]]
if ($wlan>0) do={/system script run script1} else={/system script run script2}
}
change the name of script1 and script2 for your name of scripts
 
planetcaravan
Member Candidate
Member Candidate
Topic Author
Posts: 267
Joined: Tue Aug 25, 2009 5:33 pm

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 7:41 pm

Thanks for you suggestions.
I've created a file named nuova.txt.
I've used
:if ($usewlan = "no") do={/file set nuova.txt contents="no wireless"}
and
{
local wlan [len [interface wireless find]]
if ($wlan<1) do={/file set nuova.txt contents="no wireless"}
}
but both of them don't work. What's wrong?
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 8:18 pm

is working for me:
{
local wlan [len [interface wireless find]]
if ($wlan<1) do={/file set nuova.txt contents="no wireless"}
}
try this:
put [file get nuova.txt contents ]



remember first add a file:
file print file=nuova.txt
 
planetcaravan
Member Candidate
Member Candidate
Topic Author
Posts: 267
Joined: Tue Aug 25, 2009 5:33 pm

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 8:55 pm

I'm using RouterOS 5.21 on a RB750GL.
Loot at the file attached. I've also inserted the line you suggested me.
It doesn't work fo me.
I've tried without this line
put [file get nuova.txt contents ]
but nothing's changing.

Look that, file already exists!
You do not have the required permissions to view the files attached to this post.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 9:08 pm

first paste in your terminal this
{
local wlan [len [interface wireless find]]
if ($wlan<1) do={/file set nuova.txt contents="no wireless"}
}
if the output is nothing, is all ok

and see the comment in the file with this
put [file get nuova.txt contents ]
 
planetcaravan
Member Candidate
Member Candidate
Topic Author
Posts: 267
Joined: Tue Aug 25, 2009 5:33 pm

Re: How to know if router has a wlan interface

Sat Oct 20, 2012 10:00 pm

GOT IT!
As my RB750GL doesn't have wireless package enabled, "wireless" command does not will be recognized!
I've enabled the package and all is working fine!

Thanks!
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: [SOLVED] How to know if router has a wlan interface

Sat Oct 20, 2012 10:13 pm

if my answer helped you, please give me karma =)