添加自动下载功能,功能未完善

v1.0.7
kelvinBen 4 years ago committed by Your Name
parent 8588162629
commit 6e98c99acf
  1. 14
      config.py
  2. 8
      libs/core/__init__.py
  3. 64
      libs/core/download.py
  4. 1
      libs/task/base_task.py
  5. 25
      libs/task/download_task.py

@ -83,3 +83,17 @@ web_file_suffix =[
"py" "py"
] ]
# 配置自动下载Apk文件或者缓存HTML的请求头信息
header = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0",
"Connection":"close"
}
# 配置自动下载Apk文件或者缓存HTML的请求体信息
data = {
}
# 配置自动下载Apk文件或者缓存HTML的请求方法信息,目前仅支持GET和POST
method = "GET"

@ -38,6 +38,7 @@ class Bootstrapper(object):
global app_history_path global app_history_path
global domain_history_path global domain_history_path
global excel_row global excel_row
global download_path
create_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) create_time = time.strftime("%Y%m%d%H%M%S", time.localtime())
@ -60,17 +61,22 @@ class Bootstrapper(object):
apktool_path = os.path.join(tools_dir, "apktool.jar") apktool_path = os.path.join(tools_dir, "apktool.jar")
output_path = os.path.join(script_root_dir,"out") output_path = os.path.join(script_root_dir,"out")
history_path = os.path.join(script_root_dir,"history") history_path = os.path.join(script_root_dir,"history")
download_path = os.path.join(script_root_dir,"download")
txt_result_path = os.path.join(script_root_dir,"result_"+str(create_time)+".txt") txt_result_path = os.path.join(script_root_dir,"result_"+str(create_time)+".txt")
xls_result_path = os.path.join(script_root_dir,"result_"+str(create_time)+".xls") xls_result_path = os.path.join(script_root_dir,"result_"+str(create_time)+".xls")
app_history_path = os.path.join(history_path,"app_history.txt") app_history_path = os.path.join(history_path,"app_history.txt")
domain_history_path = os.path.join(history_path,"domain_history.txt") domain_history_path = os.path.join(history_path,"domain_history.txt")
# 包名信息一致的情况不记录URL信息 ,不一致的时候记录URL信息
def init(self): def init(self):
if os.path.exists(output_path): if os.path.exists(output_path):
shutil.rmtree(output_path) shutil.rmtree(output_path)
os.makedirs(output_path) os.makedirs(output_path)
if os.path.exists(download_path):
shutil.rmtree(download_path)
os.makedirs(download_path)
if not os.path.exists(history_path): if not os.path.exists(history_path):
os.makedirs(history_path) os.makedirs(history_path)

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# Author: kelvinBen
# Github: https://github.com/kelvinBen/AppInfoScanner
import re
import os
import time
import config
import threading
import requests
import libs.core as cores
class DownloadThreads(threading.Thread):
def __init__(self, path, type):
self.url = path
self.type = type
def __requset__(self):
try:
create_time = time.strftime("%Y%m%d%H%M%S", time.localtime())
session = requests.Session()
session.mount('http://', HTTPAdapter(max_retries=3))
session.mount('https://', HTTPAdapter(max_retries=3))
session.keep_alive =False
session.adapters.DEFAULT_RETRIES = 5
urllib3.disable_warnings()
if config.method.upper() == "POST":
resp = session.post(url=self.url,params=config.data ,headers=config.headers,timeout=30)
else:
resp = session.get(url=self.url,data=config.data ,headers=config.headers,timeout=30)
if resp.status_code == requests.codes.ok:
if self.type == "apk":
count = 0
count_tmp = 0
time1 = time.time()
length = float(resp.headers['content-length'])
apk_path = os.path.join(cores.download_path, create_time+".apk")
with open(apk_path, "wb") as f:
for chunk in resp.iter_content(chunk_size = 512):
if chunk:
f.write(chunk)
count += len(chunk)
if time.time() - time1 > 2:
p = count / length * 100
speed = (count - count_tmp) / 1024 / 1024 / 2
count_tmp = count
print(name + ': ' + formatFloat(p) + '%' + ' Speed: ' + formatFloat(speed) + 'M/S')
time1 = time.time()
f.close()
else:
html_path = os.path.join(cores.download_path, create_time+".html")
html = resp.html()
with open(html_path,"w",encoding='utf-8',errors='ignore') as f:
f.write(html)
f.close()
except Exception:
break
def run(self):
threadLock = threading.Lock()
self.__get_Http_info__(threadLock)

@ -67,6 +67,7 @@ class BaseTask(object):
def __tast_control__(self): def __tast_control__(self):
task_info = {} task_info = {}
# 调用Android 相关处理逻辑 # 调用Android 相关处理逻辑
if self.types == "Android": if self.types == "Android":

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Author: kelvinBen
# Github: https://github.com/kelvinBen/AppInfoScanner
import os
import re
import config
import hashlib
from queue import Queue
import libs.core as cores
class DownloadTask(object):
def __init__(self):
self.path = path
def start(self):
input_path = self.path
if input_path.startswith("http://") or input_path.startswith("https://"):
if input_path.endswith("apk"):
# 用来下载APK或者缓存H5或者页面内容
pass
return input_path
Loading…
Cancel
Save