@REM do creat client file
for /l %%a in (2,1,%Clicount%) do (
@REM get rand ASCII code.
@REM 每个循环需要一个不同的随机字符串,并把随机字符串赋到%RANDSTR%,给其它程序使用,自撸了 python 生成随机数+pyinstaller ,打包成成 rand.exe,放在.\bin 下面
@REM 下面我按网上能找到的两种做法,CMD 环境或程序输出,获取输出内容到%RANDSTR%
@REM 做法一:
.\bin\randstr.exe -l8 -d8>.\tmp\randstr.txt
set /p RANDSTR=
#自己随手写的随机字符串,没讲究,能用就可以了
import sys
import random
import string
helpStr = """
command: randStr -option len
option:
-l Letter,'Aa-Zz'
-d Number,'0-9'
-c Chars,'@$#_%?'
"""
letters = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'
numbers = '0123456789'
chars = '@$#_%?'
if __name__ == '__main__':
if len(sys.argv) == 1:
print('Options error...')
print(helpStr)
sys.exit()
optionStr = (((''.join(sys.argv[1:])).replace(' ','')).replace('-','')).strip()
rChar = ''
if len(optionStr) >= 2:
optionList = []
tmpStr = ''
if optionStr[0].isalpha():
tmpStr = ''.join(optionStr[0])
for c in optionStr[1:]:
if c.isdigit():
tmpStr = tmpStr + c
if c.isalpha():
optionList.append(tmpStr)
tmpStr = c
else:
optionList.append(tmpStr)
set_optionList = list(set(optionList))
for i in set_optionList:
if i[0] == 'l':
for c in range(int(i[1:])):
randNum = random.randint(0, len(letters))
rChar += letters[randNum - 1]
if i[0] == 'd':
for c in range(int(i[1:])):
randNum = random.randint(0, len(numbers))
rChar += numbers[randNum - 1]
if i[0] == 'c':
for c in range(int(i[1:])):
randNum = random.randint(0, len(chars))
rChar += chars[randNum - 1]
if rChar:
rCharList = list(rChar)
random.shuffle(rCharList)
print(''.join(rCharList))
else:
print('Options error...')
print(helpStr)
sys.exit()
randstr, tmpstr, randnum, rchar