Hello
I had a request which I never thought before, but today someone asked if it is possible to automatically change the wireless password every hour, or so, and display that password on a big screen. I can’t think of any solution, I guess it would involve some work with api, but I don’t know api at all.
Anyone got any idea?
Thank you.
This is possible. You don’t have to use the API, you can use scripting. Just have the router download a file from somewhere every minute, and change the wireless password to whatever is in that file. Then, you would need some type of video controller that can do text for the TV in the same manner.
Not too difficult, but you need to do a lot of research to get everything integrated.
I see, it crossed my mind if I can do it that way.
So basically I will need to fetch a file, right? and from that then get the new value of the password?
I will give a try, although I am not that good in scripting
.
Thank you, Toni
Yes, fetch the file, read it, and then change the password to that file. You don’t have to worry if the password has changed or not, because if it hasn’t changed then when the script changes to password to the same password, no harm done.
I think I managed how to do it. Here is how.
First, I found that it was possible to generate random passwords using batch files in Windows. I found the code of this batch file on the internet:
Setlocal EnableDelayedExpansion
Set _RNDLength=8
Set _Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set _Str=%_Alphanumeric%987654321
:_LenLoop
IF NOT "%_Str:~18%"=="" SET _Str=%_Str:~9%& SET /A _Len+=9& GOTO :_LenLoop
SET _tmp=%_Str:~9,1%
SET /A _Len=_Len+_tmp
Set _count=0
SET _RndAlphaNum=
:_loop
Set /a _count+=1
SET _RND=%Random%
Set /A _RND=_RND%%%_Len%
SET _RndAlphaNum=!_RndAlphaNum!!_Alphanumeric:~%_RND%,1!
If !_count! lss %_RNDLength% goto _loop
Echo !_RndAlphaNum! >index.htm
Echo !_RndAlphaNum! >test.txt
copy test.txt \\192.168.2.254\pub
I added the last three lines to fit my needs. The first part does generate the random password made of alphanumeric and eight digits. The length of the password can be changed anyhow by modifying the value of “Set _RNDLength=8” from 8 to whatever is needed, in the code above. Then, activating the samba on routerboard, I added a copy of the generated text file from the local storage to the samba. Also, using the code above I generated an index.htm file which I plan to use as the page to be displayed on the big screen.
Then, in routerboard, I added a simple script:
/interface wireless security-profiles set wpa2-pre-shared-key= [:pick [/file get value-name=contents pub/test.txt] 0 8] 3
Of course, both the batch file and the script, can be run now by scheduling them at the same hour with a little difference from each other of about 5 seconds or something like this.
What would be a farther challenge, is if this batch file can be run from an android tablet and then displayed on the very screen of this tablet
. Or even better, can this batch file be coded using scripting in RouterOS? But at the moment, it is fine as it is.
Thank you for the help. I had never had such a request, so it was nice to get this done.