chore: 批量新增各类工具脚本与配置文件

1. 新增音频录制、下载、上传相关脚本
2. 新增数据库操作、API调用工具
3. 新增Excel数据处理脚本
4. 新增弱密码检测脚本
This commit is contained in:
2026-06-14 17:47:15 +08:00
parent aac9f5934d
commit 2d8c1ea8f9
46 changed files with 11644 additions and 829 deletions
+84 -27
View File
@@ -20,7 +20,7 @@
"port=3306,\n",
"user='root',\n",
"password='Abcd@123456',\n",
"database='hongxx_video',\n",
"database='hongxx',\n",
"charset='utf8'\n",
")\n",
"# 创建游标对象\n",
@@ -50,17 +50,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 26,
"id": "b717043a",
"metadata": {},
"outputs": [],
"source": [
"sql = 'select * from video_info'"
"sql = 'select * from sys_user where dept_id=100'\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 27,
"id": "b4b373b8",
"metadata": {},
"outputs": [],
@@ -72,46 +72,103 @@
},
{
"cell_type": "code",
"execution_count": 8,
"id": "84652b4b",
"execution_count": 28,
"id": "394495d3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[2,\n",
" 3,\n",
" 4,\n",
" 6,\n",
" 24,\n",
" 31,\n",
" 308,\n",
" 909,\n",
" 917,\n",
" 918,\n",
" 1145,\n",
" 3690,\n",
" 3698,\n",
" 3828,\n",
" 3842,\n",
" 3843,\n",
" 3844,\n",
" 3895,\n",
" 3899,\n",
" 3912,\n",
" 3913,\n",
" 3935,\n",
" 3936,\n",
" 3988,\n",
" 5440,\n",
" 5492,\n",
" 7696,\n",
" 7713,\n",
" 7714,\n",
" 7723,\n",
" 7728,\n",
" 2059454179031199746]"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[i[\"user_id\"] for i in result]\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "325e4664",
"metadata": {},
"outputs": [],
"source": [
"result\n",
"# http://192.168.0.244:88/record/original-files/video/522e4c55fc804decafdd0a62e5a1bf74.mp4\n",
"for item in result:\n",
" if item[\"video_url\"].startswith(\"http://192.168.0.244:88\"):\n",
" video_url = item[\"video_url\"].replace(\"http://192.168.0.244:88\",\"/mp4\")\n",
" sql = f\"update video_info set video_url='{video_url}' where id={item['id']}\"\n",
" cursor.execute(sql)"
" userid = item[\"user_id\"]\n",
" \n",
" sql2 = f\"update sys_user set dept_id=100, team_user_type ='BACKEND' where user_id={userid}\"\n",
" cursor.execute(sql2)\n",
"connection.commit()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "f62b4e7d",
"metadata": {},
"outputs": [],
"source": [
"for item in result:\n",
" userid = item[\"user_id\"]\n",
" sql2 = f\"update sys_user_dept set dept_id=100, person_type='hx_sys' where user_id={userid}\"\n",
" cursor.execute(sql2)\n",
"connection.commit()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b4381f4",
"id": "7dcf47b8",
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。\n",
"\u001b[1;31m请查看单元格中的代码,以确定故障的可能原因。\n",
"\u001b[1;31m单击<a href='https://aka.ms/vscodeJupyterKernelCrash'>此处</a>了解详细信息。\n",
"\u001b[1;31m有关更多详细信息,请查看 Jupyter <a href='command:jupyter.viewOutput'>log</a>。"
]
}
],
"outputs": [],
"source": [
"for item in result:\n",
" userid = item[\"user_id\"]\n",
" sql2 = f\"update sys_user_role set dept_id=100 where user_id={userid}\"\n",
" cursor.execute(sql2)\n",
"connection.commit()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
+116
View File
@@ -0,0 +1,116 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "42e17205",
"metadata": {},
"outputs": [],
"source": [
"# %%\n",
"import pymysql\n",
"\n",
"# %%\n",
"\n",
"# 创建数据库连接\n",
"connection = pymysql.connect(\n",
"host='192.168.0.244',\n",
"port=3300,\n",
"user='root',\n",
"password='hxyd1109',\n",
"database='school_server',\n",
"charset='utf8'\n",
")\n",
"cursor = connection.cursor()\n",
"# %%\n",
"def create_table(cursor,result):\n",
" \n",
" data = []\n",
" for i in result:\n",
" list_list = list(i)\n",
" des=cursor.description # 获取表详情,字段名,长度,属性等\n",
" t = \",\".join([item[0] for item in des])\n",
" table_head = t.split(',') # # 查询表列名 用,分割\n",
" \n",
" dict_result = dict(zip(table_head, list_list)) # 打包为元组的列表 再转换为字典\n",
" data.append(dict_result) # 将字典添加到list_result中\n",
" return data\n",
"\n",
"# %%\n",
"\n",
"# %%\n",
"\n",
"# %%\n",
"sql1 = \"select * from teacher where id=828\"\n",
"cursor.execute(sql1)\n",
"result=cursor.fetchall()\n",
"table_app = create_table(cursor,result)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "54db4116",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'id': 828,\n",
" 'tea_name': '彭兰英',\n",
" 'sex': 2,\n",
" 'phone': '15198039323',\n",
" 'type': 6,\n",
" 'grade_id': None,\n",
" 'class_id': None,\n",
" 'user_name': 'ptszxbr9023',\n",
" 'team_id': '110',\n",
" 'pid': None,\n",
" 'serial_no': '1336827486',\n",
" 'openid': None,\n",
" 'tea_no': 'ptszxbr9023',\n",
" 'wx_phone': '15198039323',\n",
" 'user_id': None,\n",
" 'department_id': None,\n",
" 'zt_teacher_uuid': None,\n",
" 'hire': '职工',\n",
" 'power': '门卫安保',\n",
" 'class_type_name': None,\n",
" 'hire_id': 98,\n",
" 'flag': None,\n",
" 'state': 1,\n",
" 'sync_source': 'local'}]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"table_app"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
+46
View File
@@ -0,0 +1,46 @@
import pymysql
import random
import datetime
import random
# 创建数据库连接
connection = pymysql.connect(
host='192.168.0.244',
port=3300,
user='root',
password='hxyd1109',
database='school_server',
charset='utf8'
)
# 创建游标对象
cursor = connection.cursor()
orgianl = {'id': 828,
'tea_name': '彭兰英',
'sex': 2,
'phone': '15198039323',
'type': 6,
'grade_id': None,
'class_id': None,
'user_name': 'ptszxbr9023',
'team_id': '110',
'pid': None,
'serial_no': '1336827486',
'openid': None,
'tea_no': 'ptszxbr9023',
'wx_phone': '15198039323',
'user_id': None,
'department_id': None,
'zt_teacher_uuid': None,
'hire': '职工',
'power': '门卫安保',
'class_type_name': None,
'hire_id': 98,
'flag': None,
'state': 1,
'sync_source': 'local'}
sql = f"""
UPDATE `school_server`.`teacher` SET `tea_name` = '彭兰英' WHERE `id` = 828;
"""
cursor.execute(sql)
connection.commit()
cursor.close()
connection.close()
+2 -2
View File
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"id": "b82fd271",
"metadata": {},
"outputs": [],
@@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"id": "759c550a",
"metadata": {},
"outputs": [],
+206
View File
@@ -0,0 +1,206 @@
# %%
import pymysql
import pandas as pd
import snowflake
import random
# %%
# 创建数据库连接
connection = pymysql.connect(
host='100.64.0.36',
user='root',
password='@HXYD1109mysql',
database='school_server',
charset='utf8'
)
# 创建游标对象
cursor = connection.cursor()
sql="select id,stu_name from student where team_id=19"
cursor.execute(sql)
result=cursor.fetchall()
# %%
def create_table(cursor,result):
data = []
for i in result:
list_list = list(i)
des=cursor.description # 获取表详情,字段名,长度,属性等
t = ",".join([item[0] for item in des])
table_head = t.split(',') # # 查询表列名 用,分割
dict_result = dict(zip(table_head, list_list)) # 打包为元组的列表 再转换为字典
data.append(dict_result) # 将字典添加到list_result中
return data
# %%
table = create_table(cursor,result)
# %%
# %%
sql1 = "select user_name from account"
cursor.execute(sql1)
result=cursor.fetchall()
table_app = create_table(cursor,result)
# %%
# %%
from requests import get,post
import pandas as pd
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
import threading
# %%
# 常用弱密码列表
WEAK_PASSWORDS = [
"123456a",
"123456",
"admin123",
"password",
"admin@123",
"root123",
"12345678",
"123456789",
"888888",
"666666",
"123123",
"111111",
"qwerty",
"abc123",
"1q2w3e",
"1qaz2wsx",
"a123456",
"Aa123456",
"@123456",
"Abcd1234",
"Abcd@123",
"admin",
"123321",
"000000",
"1234",
"12345",
"test123",
"pass123",
"1234567",
"1234567890",
]
BASE_URL = "http://band.hxzhxy.cn"
# 先用一个已知弱密码账号验证接口是否通畅
print("=" * 50)
print("验证接口是否通畅...")
test_param = {
"username": "zhongwei",
"password": "123456a",
"client_id": "client",
"grant_type": "password",
"client_secret": "123456",
}
try:
test_resp = get(url=f"{BASE_URL}/oauth/token", params=test_param, timeout=10).json()
if "access_token" in test_resp:
print("接口通畅,已获取测试 token")
else:
print(f"接口返回: {test_resp}")
except Exception as e:
print(f"接口请求异常: {e}")
# %%
# 线程安全的检测结果
weak_accounts = []
total_attempts = [0]
lock = threading.Lock()
def try_account_password(account_idx, username):
"""尝试单个账号的所有弱密码,返回找到的弱密码或 None"""
for pwd in WEAK_PASSWORDS:
param = {
"username": username,
"password": pwd,
"client_id": "client",
"grant_type": "password",
"client_secret": "123456",
}
with lock:
total_attempts[0] += 1
attempt = total_attempts[0]
try:
resp = get(url=f"{BASE_URL}/oauth/token", params=param, timeout=10)
data = resp.json()
if "access_token" in data:
print(f"[弱密码] 账号#{account_idx}: {username} | 密码: {pwd} | token: {data['access_token'][:20]}...")
return {
"username": username,
"password": pwd,
"token": data["access_token"],
}
except Exception as e:
print(f" [异常] #{account_idx} {username} / {pwd} -> {e}")
return None
print("=" * 50)
print(f"开始检测 {len(table_app)} 个账号的弱密码...")
print(f"弱密码列表 ({len(WEAK_PASSWORDS)} 个): {WEAK_PASSWORDS}")
print(f"线程数: 3")
print("-" * 50)
start_time = time.time()
completed = [0]
with ThreadPoolExecutor(max_workers=3) as executor:
futures = {}
for i, account in enumerate(table_app, 1):
username = account['user_name']
future = executor.submit(try_account_password, i, username)
futures[future] = i
for future in as_completed(futures):
result = future.result()
with lock:
completed[0] += 1
if completed[0] % 10 == 0:
elapsed = time.time() - start_time
print(f"[进度] 已检测 {completed[0]}/{len(table_app)} | 用时 {elapsed:.1f}s | 发现弱密码: {len(weak_accounts)}")
if result:
with lock:
weak_accounts.append(result)
elapsed_total = time.time() - start_time
# %%
# 输出检测结果
print("=" * 50)
print("检测完成!")
print(f"累计尝试 {total_attempts[0]} 次请求")
print(f"耗时: {elapsed_total:.1f}")
print(f"发现 {len(weak_accounts)} 个弱密码账号:")
print("=" * 50)
if weak_accounts:
df_weak = pd.DataFrame(weak_accounts)
# token 太长,截断显示
df_weak["token_preview"] = df_weak["token"].str[:30] + "..."
df_display = df_weak[["username", "password", "token_preview"]]
print(df_display.to_string(index=False))
# 可选:导出到 Excel
# df_weak.to_excel("weak_password_accounts.xlsx", index=False)
# print("\n结果已导出到 weak_password_accounts.xlsx")
else:
print("未发现弱密码账号")
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long