2.[文件]
passwordGenerate.py ~ 4KB
下载(13)
# -*- coding: cp936 -*-
import string
import threading
import random
import os.path
LOCK = threading.Lock()
PC = string.ascii_letters+\
string.digits+\
r"+-*/=,.;'\[]`"
TOTAL = 0
FILENAME_CHARACTER = ['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', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
def filenameGenerate():
global FILENAME_CHARACTER,FILE
filename = ''
while True:
filename = random.sample(FILENAME_CHARACTER,random.randint(0,10))
tmp = ''
for i in filename:
tmp = tmp + i
filename = tmp
if os.path.exists("password\\"+filename) == False:
break
else:
continue
return filename
FILENAME = filenameGenerate()
def func(password):
print password
global LOCK,TOTAL,FILENAME,FILE
if LOCK.acquire(1):
if TOTAL % 1000 == 0:
FILENAME = filenameGenerate()
f = open("password\\"+FILENAME,'a')
f.write(password+'\n')
f.flush()
f.close()
TOTAL = TOTAL + 1
LOCK.release()
def func1(func):
global PC
for i in range(0,len(PC)):
tmp = str(PC[i])
func(tmp)
def func2(func):
global PC
for i1 in range(0,len(PC)):
for i2 in range(0,len(PC)):
tmp = str(PC[i1])+str(PC[i2])
func(tmp)
def func3(func):
global PC
for i1 in range(0,len(PC)):
for i2 in range(0,len(PC)):
for i3 in range(0,len(PC)):
tmp = str(PC[i1])+str(PC[i2]) + str(PC[i3])
func(tmp)
def func4(func):
global PC
for i1 in range(0,len(PC)):
for i2 in range(0,len(PC)):
for i3 in range(0,len(PC)):
for i4 in range(0,len(PC)):
tmp = str(PC[i1])+str(PC[i2]) + str(PC[i3])+str(PC[i4])
func(tmp)
def func5(func):
global PC
for i1 in range(0,len(PC)):
for i2 in range(0,len(PC)):
for i3 in range(0,len(PC)):
for i4 in range(0,len(PC)):
for i5 in range(0,len(PC)):
tmp = str(PC[i1])+str(PC[i2]) + str(PC[i3])+str(PC[i4])+str(PC[i5])
func(tmp)
def func6(func):
global PC
for i1 in range(0,len(PC)):
for i2 in range(0,len(PC)):
for i3 in range(0,len(PC)):
for i4 in range(0,len(PC)):
for i5 in range(0,len(PC)):
for i6 in range(0,len(PC)):
tmp = str(PC[i1])+str(PC[i2]) + str(PC[i3])+str(PC[i4])+str(PC[i5])+str(PC[i6])
func(tmp)
if __name__ == '__main__':
group = []
#group.append(threading.Thread(target=func1,args=(func,)))
#group.append(threading.Thread(target=func2,args=(func,)))
#group.append(threading.Thread(target=func3,args=(func,)))
group.append(threading.Thread(target=func4,args=(func,)))
#group.append(threading.Thread(target=func5,args=(func,)))
#group.append(threading.Thread(target=func6,args=(func,)))
for i in group:
i.start()
while True:
error = 0
for i in group:
if i.isAlive() == False:
error = error + 1
if error == len(group):
break