Help with retrieving /interface/wireless > scan data

Hi, I need to make a script that collects data from /interface/wireless/> scan “wlan1” and sends it to the specific mail daily.

I’ve got everything figured out except for this:


:local wirelesslist [scan $interface1 freeze-frame-interval=0:0:02];

Problem with the scan is that you have to stop it manualy by hitting Q key. In the script the scan is running continously (i guess) so I’m practicly stuck in endless loop. Is there any way I could perform the scan once or simulate user Q input.

Thank you

use “duration” parameter

:global interface1 "wlan1";

:global wirelesslist1 ""; 

/interface
wireless

:global wirelesslist1 [scan $interface1 duration=5];

:log info "sending mail"

/tool
e-mail
send server="mail.something.com:25" user="user" password="somepwd" from="sender" to="recipient" subject="list" body="body with wireless lists";

this is the part of the code. It does scan the wireless networks for 5 seconds, but it doesn’t continue with execution. The log doesn’t show the input???

EDIT: I managed to proceed with executing, there is another problem (sorry, but i’m a scripting n00b).

wirelesslist1 is NULL???

how can i retrieve data returned from the scan?

This does not work either:

:foreach myVar in=[scan wlan1 duration=3] do={;
:log info "loop";
:};

neither does this

:global myVar [scan wlan1 duration=2];
:put $myVar;

Anyone?

Come on people, Ubiquiti does this well. And we’re better than them, right? How do we get this?

I have tried:

:global scanstr [/interface wireless scan wlan1 duration=10];
:put “$scanstr”;

And it does not work.

:environment print
“scanstr”=[:nothing]

Do we have to write our own scan script?

(i.e. foreach value in scanlist, do something really smart and dump it to a file or variable / when finished grab it in the dude or via ssh or push it via syslog)

Here is one solution using the newer version of Tera Term which you can get here;

http://en.sourceforge.jp/projects/ttssh2/downloads/50074/teraterm-4.68.exe/

; Filename: MikroTik_Wlan_Scan.ttl
; Tera Term Script (use newer version 4.6x)
; Author: Bob Burley - April 19, 2011

; Initialize Variables
deviceUsernamePrompt='Login:'
devicePasswordPrompt='Password:'
deviceUsername="admin"
devicePassword="xxxxxxxx"
commandPrompt='] >'
deviceIPaddress="1.1.1.1"
host=deviceIPaddress
strconcat host ':23 /nossh /T=1'
outputFilename='ScanList.txt'

; Regular Expression for matching - could still use some fine tuning
; The Band '2.4ghz-b' is hard-coded in this string and needs tweaking to allow different bands
regexStr='^\w{1,5}\s{1,5}\h{2}:\h{2}:\h{2}:\h{2}:\h{2}:\h{2}\s.{1,12}\s2\.4ghz-b\s{3}\d{4}\s-\d{2}\s-\d{2,3}\s\d{2}'

; Connect to device
connect host
wait deviceUsernamePrompt
sendln deviceUsername
wait devicePasswordPrompt
sendln devicePassword
wait CommandPrompt

; Delete previous file if present and you are not using append mode
filesearch outputFilename
if result filedelete outputFilename

; Open Output File
; Last parameter: 0 = Overwrite - 1 = Append
fileopen outputFile 'ScanList.txt' 0

; Write header lines to file
; This is manually written because these lines appear multiple times during the scan
filewriteln outputFile 'Flags: A - active, B - bss, P - privacy, R - routeros-network, N - nstreme'
filewriteln outputFile '      ADDRESS           SSID       BAND       FREQ SIG NF   SNR RADIO-NAME'

; the command prompt appears multiple times during the scan,
; so 'end' detection is done with this 3 second timeout
timeout=3

; Start the WLAN Scan and run for 5 seconds
sendln '/interface wireless scan 0 duration=5'
; flush the command just entered from the buffer
flushrecv

; detect output lines that match the Regular Expression
:loop1
waitregex regexStr
outputLine=inputstr
if result filewrite outputFile outputLine
; detect timeout
if result=0 goto exit1
goto loop1

:exit1
fileclose outputFile
sendln '/quit'

; The output file will contain duplicate entries
; Additional scripting is required to process the output file

The other day, I accidentally issued a scan on a CPE unit. It didn’t come back right away, but after a few seconds, it dumped the scan results right into my terminal window. The TCP stream survived the few seconds it took to complete the scan and re-associate with the AP.

I tried this from a mac-telnet session… it didn’t survive :frowning:

bburley:

Thanks for the script and the intro to Tera Term. I used your script and it does need a few tweaks. It has the same flaw that I am already dealing with which is that I am wanting to run the script from across the wireless link and the scan command cuts the wireless link.

if you initiate scan on wireless interface it will drop connected users and initiate scan, as you already noted, TCP connection can survive link disconnection/reconnection period and user is able to see the results. This is why duration argument was introduced so it is possible to get back fast enough, before session is taken down.

Why you (mikrotik staff) don’t enable the option to save the scans, snooper or freq.usage on a file?
As mentioned before, it doesn’t work.. It’s too difficult? :frowning:

(waiting for a serious explanation..)

I am very disappointed this feature is still not covered by MT nor anyone has been able to produce a working script that gives us the wireless scan (or other wireless tool results like snoop etc) results and prints it to a file we can have it send to mail or server for further processing.

I see several attempts in the forum but so far not a good working one. Or am I missing something here?
Its only that I really don’t seem to understand the scripting language and don’t have the time to spend loads of time to find out.
I have to run a network with all its issues. Interference in the working freq’s is my main issue nowadays and I need to find freq’s for an AP-client network that is relative free of interfering freq’s.
Running the scan on the AP is not enough because some remote clients are getting interferences from competition the AP won’t see!
Or an AP might pick up an interfering freq. with -80 or so while some distant CPE picks same ´foreign´ AP with -50 which pushes him of the air…

To visit each and every client to do a manual scan takes some weeks and it has to happen on a regular period.

A smart script should be able to do this for me remotely?

I tried these approaches:

  • RouterOS scripting
  • RouterOS API
  • I programmed application that does SSH connection to router
    and none worked. Still searching for the solution.

It would be very helpful if you could do some feature like

/interface wireless scan 0 duration=5 outputfile=something

which would scan the ether for 5 seconds and export all SSID-s to a file which we could download via sftp or something.

Another solution which would work would be some other kind of scan function (interface scans SSID-s for N seconds, and prints all SSID-s it gathered in that interval) like

/interface wireless scanonce  0 duration 5

So MT guys, any chance we could get something like this in future versions of RouterOS? It would be very helpfull…

EDIT: I managed to retrieve data via API. The thing is, API doesn’t return ROS version and flags. :frowning:

WirelessRudy has requested this on the Feature Requests page. Search for “Save wireless scan” to find it.

I would like to add my name, but the wiki is currently not accepting new accounts :frowning:

Hello,

it is also possible to connect locally and save scan output to file. Like this:
/system ssh address=127.0.0.1 port=22 command=“/in wi scan wlan1 duration=8s” output-to-file=scan.txt

With ssh-keys it should connect without asking for password.

Hey everyone…I am going to revive this thread. Has someone, or has mikrotik, implemented the ability to do a remote scan or a scan and save to text file which can be emailed (maybe parsed elsewhere to make presentable). I have tinkered with this for hours, searched for hours and have not had any luck finding something for scan or frequency-scan or the best one would be a snoop for “n” for network scan.

2016 and we have nothing about this feature yet?

how to choose a clear channel if we can’t see the other end remotely ?

Would be very very very very nice if Mikrotik Staff could implement something like this, but before the miraculous version 7 come out.

Have you noticed the background scan function?

What use is the background scan function?

  1. It is not possible on a ‘station-mode’ unit.
  2. ac units don’t support scan function.
  3. The scan function itself doesn’t ‘see’ all. For instance it doesn’t see ubnt equipment with frequency shift.
    3b The scan only ‘sees’ 20Mhz or wider channels. Any usage of 5 and 10Mhz is won’t see unless set in the “Channels” portion and in the “Scan list”.
  4. To have the scan performing a scan in the band you work in you have to set that range in the “Scan list” part of the wireless config and as a result the unit has to scan in that whole band after a disconnect to connect again which can take up several 10ths of seconds. If client has PPoE tunnel the tunnel is broken and if PPoE server uses dynamic IP’s their is a good change the station has a new IP assigned. Your winbox connection to the client is lost and with it all possible scan data.
  5. ‘Scan’ only ‘sees’ 802.11a/n/c or b/g protocol radio signals.
    Mikrotik indeed is running way behind on most competitors in regard of scan functionality.
    To fight interference around clients you need to know what the spectrum is doing there. So you need a spectral scan. Now you can spend several hundreds of dollars into a spectral scanner and go to the clients location every time you need to perform a scan but that ain’t workable.
    In present day’s situation you need to perform regurlar spectral checks on a monthly base. Client units should have something made available. If not this is just another reason why user move away to another platform…
  1. Not true. Just tested on such station (actually station-bridge mode): station scanned while there was uninterrupted traffic flowing both ways and the winbox was connected over the scanning wlan.
  2. Not true. Really funny idea to have a client without working scan. How could it connect to ap without it?
  3. Does not see airmax. Like ubnt does not see nv2, because the protocols ar proprietary. Not sure how superchannel works on ac, so I cannot say.

Generally, why you think that this topic is about ac?