ASK [random wifi password generator]

i’m using script for “random wifi password generator.”

i got two scripts. Both of them are working.

if i ll run the script every 10-15 min it does work well.

Problem:
Weekly it doesn’t work.
Script sending me same wifi password from the last ran.

i have attached both scripts.
2.txt (2.82 KB)
1.txt (2.59 KB)

When I run the script 1.txt from cli, I do get a “random” password every time.
But if you run the script scheduled, it will not be random, since it uses hour/minutes/seconds to make the random, and this will be the same if you set it to run once a week etc.

PS you should post the script using code tags </> like this:


1.txt

{
:local wifiprofile wifi_security_profile
:local toEmail yourmail@domain.com

:local time [:pick [/system clock get time] 0 2];
:local min [:pick [/system clock get time] 3 5];
:local sec [:pick [/system clock get time] 6 8];
:local char;
:set char ( $char . [ :pick $time 1 ] . [ :pick $time 0 ]);
:local char1;
:set char1 ( $char1 . [ :pick $min 1 ] . [ :pick $min 0 ]);
:local char2;
:set char2 ( $char2 . [ :pick $sec 1 ] . [ :pick $sec 0 ]);
:local arrayalpha ("2","C","h","Y","!","f","j","c","}","q","k",":","(","}","3","Y","T","|","C","v","}","n","8","I","r","4","p","V","6",":","S","V","=","p","Z","T","6",")","l",":","K","b","=","Y","7","X","c","P","@","g","m","U","T","_","g","v","N","j","E","g","f","D","h","!","W","p","U","z","T","S","}","h","M","Y","i","E","c","4","!","Q","(","<","Y","h","@","e","q","7","]","l","R","-","h","S","w","(",">","/","r","=","<","I","&","5","@","!","|","h","p","l","1","Y","U","2","J","R","T","Y","}","=","b","c","$","9","d","e","@","S","6","W","B","Q","$","S","b","p","}","3","m","X","g","8","y","j","h","S","Z","F","@","!","t","}","!","U","j","/","W","5","}","a","g","!","S","S","T","{","7","f","G","W","T","_","/","k","3","+","T","X","p","m","!","e","i","L","]","3","d","G","T","+","@","H","!","Q","k","X","@","P","Q","+","k","f","K","T","S","{","Q","W","S","<","S","z","z","k","V","@","X","{","4","g","t","X","1","h","5","k","T","_","f","i","{","]","(","Y","/","1","j","h","l","]","S","3","b","Y",":","i","T","j","h","T","7","w","g","D","X","g","T","T","i","|","S","R","!","}","D","d","c","h","d","T","l","N",")","V","u","Z","T","}",":","{","S","m","Z","d","}","Z","Z","S","Y","|","_","d","k","v","h","(","7","/","-");
:local new;
:set new ( $new . [ :pick $arrayalpha ($time+$min+$sec) ] . [ :pick $arrayalpha ($time+$sec) ] . [ :pick $arrayalpha ($min+$sec) ] . [ :pick $arrayalpha $sec ] . [ :pick $arrayalpha $char ] . [ :pick $arrayalpha $char1 ] . [ :pick $arrayalpha $char2 ] . [ :pick $arrayalpha ($char+$char1+$char2) ]);
:local arrlengh [:len $arrayalpha];
:put "Our Array Lengh is $arrlengh Your New String is $new";
}

RouterOS does not have a random function. Many has tried to make script to make random text, but all seems to be flawed.

But this should do, since it gets the string from an external site:

{
/tool fetch url="https://www.random.org/passwords/\?num=1&len=8&format=plain&rnd=new" keep-result=yes dst-path="pass.txt"
:local pass [/file get pass.txt contents]
:put $pass
}

EDIT
No need to use a file. This should do:

{
local pass ([/tool fetch url="https://www.random.org/passwords/\?num=1&len=20&format=plain&rnd=new" output=user as-value]->"data")
:put $pass
}

if i’ll use the first you edit, it will work weekly?

second part that you have posted.
So far i don’t have any particular website that i can put in

You can use both script in my latest post. Only difference is that one writes to file before it sets the variable.
RouterOS needs to have access to internet for this to work, but should be better than using time to generate a random text.

What about 1.text after you have edited, would be fine?

at this point i need some script which will send email and change wifi sec profile

Do not use. I only changed so that it show up on display.
It is not a random tool, it wil gave same code every time if its run at the same time of day.

Use this one:

local pass ([/tool fetch url="https://www.random.org/passwords/\?num=1&len=20&format=plain&rnd=new" output=user as-value]->"data")
:put $pass

i need some script which will send email and change wifi sec profile

I do not have a wifi device nearby, but this may work:

# Set your wifi profile
:local wifiprofile set_your_profile

# Set your email
:local toEmail my.emai@gmail.com

# Gets a new password
:local new ([/tool fetch url="https://www.random.org/passwords/\?num=1&len=20&format=plain&rnd=new" output=user as-value]->"data")

# Set password to wifi profile
:interface wireless security-profiles set $wifiprofile wpa-pre-shared-key="$new"
:interface wireless security-profiles set $wifiprofile wpa2-pre-shared-key="$new"

# Send email
:tool e-mail send to=$toEmail subject="$[/system identity get name] WiFi Password" body="This Week's Wireless Password Is: $new"

# Write a log line
:log info message="Wifi password for profile $wifiprofile has ben set to $new"

unfortunately..it doesn’t work

It fail and do not run, or does not set password or does not send emai?

it doesn’t do anything

Cut an past this to terminal of your Router, do you get a password:

{
:local new ([/tool fetch url="https://www.random.org/passwords/\?num=1&len=20&format=plain&rnd=new" output=user as-value]->"data")
:put $new
}

yes im getting pass

Then try

:interface wireless security-profiles print

to get then name of your profile.

Then run after change your_profile to your profile

:interface wireless security-profiles set your_profile wpa2-pre-shared-key="test"

Does this work?

NB I do not have Wifi device so need to take on test at a time.

If all above work try to cut and past this (aftter change to your_profile

{
:local new ([/tool fetch url="https://www.random.org/passwords/\?num=1&len=20&format=plain&rnd=new" output=user as-value]->"data")
:interface wireless security-profiles set your_profile wpa2-pre-shared-key="$new"
}

how can i combine all together?

I split it up, so I could see what does not work.

If you have more than one line of commands, you need to wrap then in {} or to run from terminal. In script this is not needed.

Not work on terminal

:local test 123
:put $test

This work

{
:local test 123
:put $test
}

i found this one it does work. Any update that you can do on this?
it will work weekly?

Set your wifi profile

:local wifiprofile set_your_profile

Set your email

:local toEmail mail@gmail.com

Gets a new password

:local pass ([/tool fetch url=“https://www.random.org/passwords/?num=1&len=20&format=plain&rnd=new” output=user as-value]->“data”)
:put $pass

Set password to wifi profile

:interface wireless security-profiles set $wifiprofile wpa-pre-shared-key=“$pass”
:interface wireless security-profiles set $wifiprofile wpa2-pre-shared-key=“$pass”

Send email

:tool e-mail send to=$toEmail subject=“$[/system identity get name] WiFi Password” body=“This Week’s Wireless Password Is: $pass”

Write a log line

:log info message=“Wifi password for profile $wifiprofile has ben set to $pass”

Its more or less the same as I wrote above. Use code tags around your script. Select code and click the </> button.

:put $pass
is not needed.

You need to create a schedule for it to run weekly.