[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] [已解决]批处理如何批量生成随机长度的随机字母数字符号组成的密码?

本帖最后由 pcl_test 于 2016-8-17 23:08 编辑

需要批量输出随机长度随机字母数字密码,网上找到份,可以设置 数字,数字字母,数字字母符号,生成个数,

但是长度写死了,只能生成10位的,不止从何修改,使他能够随机7-13位长度,附上找到的代码
  1. @echo off& setlocal enabledelayedexpansion
  2. mode con cols=60 lines=10& color 0a& title .
  3. del smile.txt 2>nul& echo.1.纯数字      2.数字英文    3.数字英文符号
  4. set /p wind=选择序号:& echo. & set /p snow=输入生成组合个数:
  5. 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)
  6. 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
  7. set m%%1=!m%%1!!n%%2!)
  8. cls& echo %%1/%snow%& echo !m%%1!>>smile.txt))
  9. 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
  10. call set m%%1=!m%%1!%%x!n%%2!%%)
  11. cls& echo %%1/%snow%& echo !m%%1!>>smile.txt))
  12. if "%wind%"=="3" (more +14 "%~F0">smile.vbs& smile.vbs %snow%&& del smile.vbs)
  13. if exist smile.txt (start "" "smile.txt")else mshta vbscript:msgbox("输入错误")(close)
  14. exit
  15. 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","~","!","@","#","$","%","^","&","*","(",")","_","+","|","[","]","{","}",";","'",":",",",".","/","<",">","?")
  16. for i = 1 to wscript.arguments(0)
  17. for j = 1 to 10
  18. Randomize
  19. y=int(1000000*rnd mod 89)
  20. n=n & x(y): next
  21. n=n & vbcrlf: next
  22. createobject("scripting.filesystemobject").opentextfile("smile.txt",2,true).writeline n
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

  1. @echo off&setlocal enabledelayedexpansion
  2. set /a ra=%random%%%6+7
  3. set tmp=0123456789abcdefghijklmnopqrstuvwxyz
  4. for /f %%a in (1 1 %ra%) do (
  5.     set /a "n=!random!%%36"
  6.     for %%z in (!n!) do set str=!str!!tmp:~%%z,1!
  7. )
  8. echo 密码为%str%
  9. pause>nul
复制代码

TOP

本帖最后由 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之间的数字
  1. @echo off&del temp.txt 2>nul
  2. set ".a=`~!@#$%%^&*()-_=+\|/{}[]:;'<>?,.""
  3. set ".b=0123456789"&set ".c=abcdefghijklmnopqrstuvwxyz"&set ".d=ABCDEFGHIJKLMNOPQRSTUVWXYZ"&set/a #a=32,#b=10,#c=26,#d=26&echo;字符集分类,等号前字母为类名称:&set .&echo;
  4. setlocal enabledelayedexpansion
  5. set/p e=n字符不重复,请输入组合,以空格分隔:
  6. for %%a in (%e%) do (
  7.     if defined .%%a set "m=!m!!.%%a!"&set/a #m+=#%%a
  8.     if /i "%%a"=="n" set #n==
  9. )
  10. if defined #n echo;警告,您设置的字符长度不得小于%#m%
  11. set/p f=请输入固定长度,0为随机长度7-13:&set/p g=请输入数量:
  12. for /l %%a in (1,1,%g%) do call:x
  13. start temp.txt&exit
  14. :x
  15. setlocal enabledelayedexpansion
  16. if "%f%"=="0" (set/a w=%random%%%7+7) else set w=%f%
  17. :y
  18. set/a x+=1
  19. :z
  20. set/a y=%random%%%#m
  21. if defined #n (if defined _%y% (goto:z) else set _%y%==)
  22. set "z=!z!!m:~%y%,1!"
  23. if %x% lss %w% (goto:y) else >>temp.txt echo;!z!
复制代码
1

评分人数

寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

运行了,输入a,回车,0,回车,100,回车,一闪就没了,也没在文件夹留下什么。。。。

TOP

4# jzsgyml


for /l %%a in (1,1,%g%) do call:x时少打了%%a,已修改
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

感谢,运行没问题!
简单的几个代码,竟然完成如此强大完善的功能,太厉害了!

TOP

返回列表