标题: [文本处理] [已解决]批处理如何批量生成随机长度的随机字母数字符号组成的密码? [打印本页]
作者: jzsgyml 时间: 2011-4-14 13:01 标题: [已解决]批处理如何批量生成随机长度的随机字母数字符号组成的密码?
本帖最后由 pcl_test 于 2016-8-17 23:08 编辑
需要批量输出随机长度随机字母数字密码,网上找到份,可以设置 数字,数字字母,数字字母符号,生成个数,
但是长度写死了,只能生成10位的,不止从何修改,使他能够随机7-13位长度,附上找到的代码- @echo off& setlocal enabledelayedexpansion
- mode con cols=60 lines=10& color 0a& title .
- del smile.txt 2>nul& echo.1.纯数字 2.数字英文 3.数字英文符号
- set /p wind=选择序号:& echo. & set /p snow=输入生成组合个数:
- for %%1 in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)do (set /a x+=1&& set x!x!=%%1)
- if "%wind%"=="1" (for /l %%1 in (1 1 %snow%)do (for /l %%2 in (1 1 10)do (set /a n%%2=!random! %% 10
- set m%%1=!m%%1!!n%%2!)
- cls& echo %%1/%snow%& echo !m%%1!>>smile.txt))
- if "%wind%"=="2" (for /l %%1 in (1 1 %snow%)do (for /l %%2 in (1 1 10)do (set /a n%%2=!random! %% 62 +1
- call set m%%1=!m%%1!%%x!n%%2!%%)
- cls& echo %%1/%snow%& echo !m%%1!>>smile.txt))
- if "%wind%"=="3" (more +14 "%~F0">smile.vbs& smile.vbs %snow%&& del smile.vbs)
- if exist smile.txt (start "" "smile.txt")else mshta vbscript:msgbox("输入错误")(close)
- exit
- x=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","~","!","@","#","$","%","^","&","*","(",")","_","+","|","[","]","{","}",";","'",":",",",".","/","<",">","?")
- for i = 1 to wscript.arguments(0)
- for j = 1 to 10
- Randomize
- y=int(1000000*rnd mod 89)
- n=n & x(y): next
- n=n & vbcrlf: next
- createobject("scripting.filesystemobject").opentextfile("smile.txt",2,true).writeline n
复制代码
作者: CrLf 时间: 2011-4-14 13:26
- @echo off&setlocal enabledelayedexpansion
- set /a ra=%random%%%6+7
- set tmp=0123456789abcdefghijklmnopqrstuvwxyz
- for /f %%a in (1 1 %ra%) do (
- set /a "n=!random!%%36"
- for %%z in (!n!) do set str=!str!!tmp:~%%z,1!
- )
- echo 密码为%str%
- pause>nul
复制代码
作者: hanyeguxing 时间: 2011-4-14 20:33
本帖最后由 hanyeguxing 于 2011-4-15 01:02 编辑
可以自由组合字符类、可以设置重复与否、可以设置固定长度或随机值,可以设置字符串数量
1,如果要变更随机范围,可以修改 set/aw=%random%%%7+7
2,如果要增加字符,可以修改 set ".a=`~!@#$%%^&*()-_=+\|/{}[]:;'<>?,."" ,并同时修改 set/a #a=32,#b=10,#c=26,#d=26 中 #b 的值
使用:
例如要求字符为数字及小写字母且在每个生成的字符串内不重复使用,第一次提示时输入b c n
要求字符长度为,第二次提示时输入10
如果输入为0,则自动随机分配一个7-13之间的数字- @echo off&del temp.txt 2>nul
- set ".a=`~!@#$%%^&*()-_=+\|/{}[]:;'<>?,.""
- set ".b=0123456789"&set ".c=abcdefghijklmnopqrstuvwxyz"&set ".d=ABCDEFGHIJKLMNOPQRSTUVWXYZ"&set/a #a=32,#b=10,#c=26,#d=26&echo;字符集分类,等号前字母为类名称:&set .&echo;
- setlocal enabledelayedexpansion
- set/p e=n字符不重复,请输入组合,以空格分隔:
- for %%a in (%e%) do (
- if defined .%%a set "m=!m!!.%%a!"&set/a #m+=#%%a
- if /i "%%a"=="n" set #n==
- )
- if defined #n echo;警告,您设置的字符长度不得小于%#m%
- set/p f=请输入固定长度,0为随机长度7-13:&set/p g=请输入数量:
- for /l %%a in (1,1,%g%) do call:x
- start temp.txt&exit
- :x
- setlocal enabledelayedexpansion
- if "%f%"=="0" (set/a w=%random%%%7+7) else set w=%f%
- :y
- set/a x+=1
- :z
- set/a y=%random%%%#m
- if defined #n (if defined _%y% (goto:z) else set _%y%==)
- set "z=!z!!m:~%y%,1!"
- if %x% lss %w% (goto:y) else >>temp.txt echo;!z!
复制代码
作者: jzsgyml 时间: 2011-4-14 22:01
运行了,输入a,回车,0,回车,100,回车,一闪就没了,也没在文件夹留下什么。。。。
作者: hanyeguxing 时间: 2011-4-15 01:01
4# jzsgyml
for /l %%a in (1,1,%g%) do call:x时少打了%%a,已修改
作者: jzsgyml 时间: 2011-4-15 19:03
感谢,运行没问题!
简单的几个代码,竟然完成如此强大完善的功能,太厉害了!
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |