初次提交

This commit is contained in:
2025-01-22 13:12:33 +08:00
commit 70f8ad025a
18 changed files with 1275 additions and 0 deletions

13
Python/Readme.md Normal file
View File

@@ -0,0 +1,13 @@
# 自己搞的小东西
- 不建议使用,性能极差
- 如果你非要用
- 你可以使用下面的命令进行打包可在所有电脑运行
```python
pyinstaller --onefile main.py
```

145
Python/UNPKG/main.py Normal file
View File

@@ -0,0 +1,145 @@
import requests
import re
import os
import shutil
import time
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
# 配置
url = "https://unpkg.ovofish.com/"
headers = {
'Accept-Language': 'zh-CN,zh;q=0.8',
'Content-Type': 'text/html; Charset=utf-8',
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
}
# 输入模块名
mod = input("请输入模块名:")
# 设置重试机制
def requests_retry_session(
retries=3,
backoff_factor=0.3,
status_forcelist=(500, 502, 504),
session=None,
proxies=None
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
if proxies:
session.proxies.update(proxies)
return session
# 获取HTML
def getHTML(url, encoding='utf-8', proxies=None):
try:
with requests_retry_session(proxies=proxies).get(url, headers=headers) as rd:
rd.encoding = encoding
rd.raise_for_status()
return rd.text
except requests.exceptions.RequestException as e:
print(f"获取HTML时发生错误: {e}")
return None
# 获取版本
def getVsions(m, proxies=None):
h = getHTML(url + m + '/', proxies=proxies)
j = re.findall(r'<select name="version"(.*?)</select>', h, re.S)[0]
patt = re.compile(r'<option.+?>(.+?)</option>')
option = patt.findall(j)
return option
# 扫描目录
def getPaths(v, p='/', files=[], folders=[], proxies=None):
h = getHTML(url + v + p, proxies=proxies)
t = re.findall(r'<table(.*?)</table>', h, re.S)[0]
href = re.findall('href="(.*?)"', t)
for name in href:
path = p + name
if name in ['../', 'LICENSE'] or path in ['/src/', '/packages/', '/types/', '/dist/docs/', '/docs/',
'/samples/', "/test/", "/locale/"]: # 跳过
continue
print(path)
if name[-1] == '/':
folders.append(path)
getPaths(v, path, files, folders, proxies)
else:
files.append(path)
return {"files": files, "folders": folders}
# 创建目录
def makeDirs(dirs, p):
if p is None:
p = './'
for i in dirs:
path = p + i
if not os.path.exists(path):
print("创建目录", path)
os.makedirs(path)
# 下载文件
def download(url, path=None, proxies=None):
try:
with requests_retry_session(proxies=proxies).get(url, proxies=proxies) as r:
r.raise_for_status()
if not os.path.exists(path):
print("下载:", url)
t = str(time.time()) + '.' + str(os.getpid()) + '.tmp'
with open(t, 'wb') as tmp_file:
tmp_file.write(r.content)
os.rename(t, path)
else:
print("文件已存在")
except requests.exceptions.RequestException as e:
print(f"下载文件时发生错误: {e}")
# 获取所有版本并展示
versions = getVsions(mod)
print("所有版本:", versions)
# 选择版本
version = input("请输入版本号(留空使用最新版):") or versions[-1]
print("选择的版本:", version)
# 构建版本路径
version_path = mod + '@' + version
# 检查当前目录是否存在该版本
if os.path.exists(version_path):
print(f"版本 {version_path} 已存在,不再下载。")
else:
# 使用代理
proxies = None
use_proxy = input("是否使用代理?(输入 'y''n': ").lower()
if use_proxy == 'y':
# 获取代理设置
default_proxy_host = "10.10.50.210" # 设置默认代理主机
default_proxy_port = 65115 # 设置默认代理端口
proxy_host = input(f"请输入代理主机 (默认为 {default_proxy_host}): ") or default_proxy_host
proxy_port = int(input(f"请输入代理端口 (默认为 {default_proxy_port}): ") or default_proxy_port)
proxy_username = input("请输入代理用户名(如果不需要身份验证,直接回车): ")
proxy_password = input("请输入代理密码(如果不需要身份验证,直接回车): ")
# 设置代理
proxies = {
'http': f'socks5://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}' if proxy_username else f'socks5://{proxy_host}:{proxy_port}',
'https': f'socks5://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}' if proxy_username else f'socks5://{proxy_host}:{proxy_port}'
}
paths = getPaths(version_path, proxies=proxies)
makeDirs(paths["folders"], version_path)
for i in paths["files"]:
u = url + version_path + i
download(u, version_path + '/' + i, proxies)
print("下载完成")

View File

@@ -0,0 +1,20 @@
certifi==2024.7.4
charset-normalizer==3.3.2
colorama==0.4.6
colorlog==6.8.2
hjson==3.1.0
idna==3.7
mcdreforged==2.13.1
packaging==24.1
parse==1.20.2
prompt_toolkit==3.0.47
psutil==6.0.0
py-cpuinfo==9.0.0
PySocks==1.7.1
requests==2.32.3
resolvelib==1.0.1
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
typing_extensions==4.12.2
urllib3==2.2.2
wcwidth==0.2.13

View File

@@ -0,0 +1,9 @@
# 来电邮箱提示
## 前言
本人买了雷迪司的UPS这东西挺好有停电提醒同时也有来电提醒但是不知道为什么来电提醒不生效所以自己整了一个
## QAQ
如果你的UPS也存在这种问题不妨也用这个曲线救国试试

8
Python/Ups-Smtp/build.py Normal file
View File

@@ -0,0 +1,8 @@
# build.py
import PyInstaller.__main__
PyInstaller.__main__.run([
'ups-test.py', # Python脚本文件名
'--onefile', # 生成单个可执行文件
])

View File

@@ -0,0 +1,54 @@
import os
import smtplib
from email.mime.text import MIMEText
from datetime import datetime
def send_email(subject, message, recipient):
sender = "syayuri@xbox.email.cn"
password = "3NCjnCAcMJEFM7db"
# 设置邮件内容
email = MIMEText(message)
email["Subject"] = subject
email["From"] = sender
email["To"] = recipient
# 连接SMTP服务器
with smtplib.SMTP_SSL("smtp.email.cn", 465) as server:
# 登录SMTP服务器
server.login(sender, password)
# 发送邮件
server.sendmail(sender, [recipient], email.as_string())
print("邮件发送成功!")
def main():
command = "baidu.com" # 替换为要ping的域名或IP地址
recipient = "mirai@lolicon.team" # 替换为要发送邮件的邮箱地址
subject = "UPS输入市电恢复" # 替换为邮件主题
# 动态生成DateTime内容
now = datetime.now()
datetime_str = now.strftime("%Y-%m-%d %H:%M:%S")
message = f"""
来自 USB790470F_ID
事件: UPS输入市电异常
类型: 输入事件;
Contact: syayuri@xbox.email.cn;
DateTime: {datetime_str}
""" # 替换为要发送的邮件内容
ping_result = 1
while ping_result != 0:
# 执行ping命令
ping_result = os.system(f"ping -c 1 {command}")
if ping_result == 0:
# ping成功发送电子邮件
send_email(subject, message, recipient)
else:
print("Ping失败正在重试...")
if __name__ == "__main__":
main()

11
Python/dns-ip/Readme.md Normal file
View File

@@ -0,0 +1,11 @@
# 用于dnspod公共DNS绑定
- 自带拦截规则
- 支持电脑的53端口直接用
- 相应快
- 每月300万次请求/FREE
- 个人用完全足够,但多人就不行了
## 该项目有什么用
本项目通过监听本机IP变动进行主动绑定保持规则可用性

54
Python/dns-ip/main.py Normal file
View File

@@ -0,0 +1,54 @@
import requests
import time
import json
def get_current_ip():
try:
response = requests.get("https://archive.ovofish.com/api/center/ipsee/")
data = response.json()
print("API响应", data) # 打印完整的API响应
return data["ip"]
except KeyError:
print("API返回的JSON格式不正确未找到'ip'键。")
return None
except Exception as e:
print(f"发生错误:{e}")
return None
def perform_action(ip):
if ip is not None:
# 执行你的操作,访问 https://link.dns.pub/
# 你可以使用 requests.get() 或其他适当的方法
url = "https://link.dns.pub/"
try:
response = requests.get(url)
# 在这里可以添加处理响应的代码,例如检查状态码、打印内容等
print(f"执行操作,访问 {url}当前IP: {ip}")
except Exception as e:
print(f"执行操作时发生错误:{e}")
else:
print("无法获取有效的IP地址跳过执行操作。")
def main():
current_ip = get_current_ip()
# 初始操作
perform_action(current_ip)
while True:
time.sleep(120)
new_ip = get_current_ip()
if new_ip is not None and new_ip != current_ip:
print("IP 已更改,执行操作")
# 执行操作
perform_action(new_ip)
current_ip = new_ip
else:
print("IP 未更改,继续等待")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,49 @@
# 用于监听本机网络波动
- 监测网络波动
- URL传输到服务器数据库中存储日志
- 可本地文件存储
- 仅检测
## 该项目有什么用
方便投诉你的运营商,让其网络保持稳定
## 如何使用
所需环境`ping3`
```python
pip install ping3
```
你需要准备一个`config.json`
```json
{
"target_ips": {
"需要ping的IP": {"location": "位置", "threshold_ms": 设置阈值, "log_method": "触发"},
"需要ping的IP": {"location": "位置", "threshold_ms": 设置阈值, "log_method": "触发"},
"需要ping的IP": {"location": "位置", "threshold_ms": 设置阈值, "log_method": "触发"}
}
}
```
示例
```json
{
"target_ips": {
"10.10.50.1": {"location": "Home", "threshold_ms": 10, "log_method": "url"},
"10.10.51.1": {"location": "Home2", "threshold_ms": 30, "log_method": "url"},
"10.10.92.1": {"location": "Home3", "threshold_ms": 100, "log_method": "url"}
}
}
```
阈值单位为MS请根据你的网络环境进行调整
超出该阈值时则触发条件
log_method`file`,`url`,`console`

77
Python/ping-logs/main.py Normal file
View File

@@ -0,0 +1,77 @@
import time
from ping3 import ping
import requests
import json
import sys
import io
# 设置标准输入输出为UTF-8编码
sys.stdout.reconfigure(encoding='utf-8')
sys.stdin.reconfigure(encoding='utf-8')
def load_config():
with open("config.json", "r", encoding="utf-8") as config_file:
config_data = json.load(config_file)
return config_data["target_ips"]
def continuous_ping(ip_addresses):
while True:
for ip_address, data in ip_addresses.items():
location = data["location"]
threshold_ms = data["threshold_ms"]
log_method = data["log_method"]
delay = ping(ip_address)
if delay is not None:
# print(f'Ping delay to {location} ({ip_address}): {delay * 1000:.2f} ms')
delay = int(delay * 1000)
else:
print(f'{time.strftime("%Y-%m-%d %H:%M:%S")}Ping to {location} ({ip_address}) failed.')
delay = 0 # 或者设定其他默认值
if delay is not None and delay > threshold_ms:
log_message = f'High latency detected for {location} ({ip_address})! Delay: {delay}ms'
if log_method == "file":
try:
with open(f'{location}_ping_log.txt', 'a', encoding="utf-8") as log_file:
log_file.write(f'{time.strftime("%Y-%m-%d %H:%M:%S")}\t{ip_address}\t{delay}ms\n')
except Exception as e:
print(f'Error writing to file: {e}')
elif log_method == "console":
print(log_message)
elif log_method == "url":
target_url = "https://archive.ovofish.com/api/center/ping-logs/"
payload = {"location": location, "ip_address": ip_address, "delay": delay}
headers = {"Content-Type": "application/json"}
try:
response = requests.post(target_url, data=json.dumps(payload), headers=headers)
if response.status_code == 200:
print(f'Delay information sent to {target_url} successfully.')
else:
print(f'Failed to send delay information to {target_url}. Status code: {response.status_code}')
# 获取返回的 JSON 数据
try:
error_json = response.json()
print(f'Error JSON: {error_json}')
except json.JSONDecodeError:
print('Failed to decode error JSON.')
except Exception as e:
print(f'Error sending delay information to {target_url}: {e}')
else:
pass
time.sleep(1)
if __name__ == "__main__":
# 判断是否有配置文件
try:
with open("config.json", "r") as config_file:
config_data = json.load(config_file)
except FileNotFoundError:
print("配置文件不存在,请检查文件路径。")
exit(1)
print("正在运行...")
target_ips = load_config()
continuous_ping(target_ips)

View File

View File

@@ -0,0 +1,149 @@
import requests
from bs4 import BeautifulSoup
import re
import json
import os
import hmac
from hashlib import sha1
print("Start downloading file links...")
# 发送GET请求获取页面内容
url = "https://teamspeak.com/zh-CN/downloads/"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
# 找到所有<a>标签并提取链接
links = soup.find_all("a", href=True)
# 匹配包含"https://files.teamspeak-services.com"的链接
file_links = [link["href"] for link in links if re.search(r"https://files.teamspeak-services.com", link["href"])]
# 按版本划分链接
ver3_links = [link for link in file_links if re.search(r"\/3\.\d+\.\d+\/", link)]
ver5_links = [link for link in file_links if re.search(r"\/(?:5\.\d+\.\d+|5\.\d+\.\d+\-\w+)/", link)]
# 设置全局变量
download_file = True
file_updated = False
# 创建版本文件夹并保存链接
def save_links_to_folder(links, folder_name):
folder_path = os.path.join(os.getcwd(), "file", folder_name)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
for link in links:
file_name = link.split("/")[-1]
file_path = os.path.join(folder_path, file_name)
# 检查文件是否需要更新
global download_file
if os.path.exists(file_path):
response = requests.head(link)
remote_file_size = int(response.headers.get('Content-Length', 0))
local_file_size = os.path.getsize(file_path)
if remote_file_size == local_file_size:
download_file = False
print(f"文件 {file_name} 已更新。无需下载。")
else:
download_file = True
os.remove(file_path)
# 如果需要下载文件
if download_file:
with open(file_path, "wb") as file:
response = requests.get(link)
file.write(response.content)
print(f"文件 {file_name} 已下载到 {folder_name}")
# 保存链接到对应版本文件夹中
save_links_to_folder(ver3_links, "Ver3")
save_links_to_folder(ver5_links, "Ver5")
# 将链接存储为JSON文件
data = {"Ver3": ver3_links, "Ver5": ver5_links}
with open("file_links.json", "w") as json_file:
json.dump(data, json_file, indent=4)
print("链接已保存至file_links.json")
def downloadFile():
global file_updated
if download_file:
print("download_file的值为:", download_file)
file_updated = True
else:
print("download_file的值为:", download_file)
file_updated = False
downloadFile()
print("file_updated的最终值为:", file_updated)
# 生成本地文件下载链接
base_download_url = "https://file-teamspeak-download.lolicon.team/file/"
def generate_local_download_links(links, folder_name):
local_download_links = [base_download_url + folder_name + "/" + link.split("/")[-1] for link in links]
return local_download_links
ver3_local_download_links = generate_local_download_links(ver3_links, "Ver3")
ver5_local_download_links = generate_local_download_links(ver5_links, "Ver5")
# 将本地文件下载链接存储为JSON文件
local_download_links_data = {"Ver3": ver3_local_download_links, "Ver5": ver5_local_download_links}
with open("local_download_links.json", "w") as local_json_file:
json.dump(local_download_links_data, local_json_file, indent=4)
print("本地下载链接已保存至local_download_links.json")
# 判断是否有文件更新
if file_updated:
print("文件已更新开始预热CDN...")
# 预热 CDN
def dogecloud_api(api_path, data={}, json_mode=False):
print('正在调用多吉云 API...')
access_key = '' # 请将此处替换为你的多吉云 Access Key
secret_key = '' # 请将此处替换为你的多吉云 Secret Key
# 如果没有 access_key 和 secret_key则跳过下面所有操作
if not access_key or not secret_key:
print('请填写多吉云 Access Key 和 Secret Key。')
return None
body = ''
mime = ''
if json_mode:
body = json.dumps(data)
mime = 'application/json'
else:
body = urllib.parse.urlencode(data)
mime = 'application/x-www-form-urlencoded'
sign_str = api_path + "\n" + body
signed_data = hmac.new(secret_key.encode('utf-8'), sign_str.encode('utf-8'), sha1)
sign = signed_data.digest().hex()
authorization = 'TOKEN ' + access_key + ':' + sign
response = requests.post('https://api.dogecloud.com' + api_path, data=body, headers={
'Authorization': authorization,
'Content-Type': mime
})
return response.json()
api_path = '/cdn/refresh/add.json'
data = {
'rtype': 'prefetch',
'urls': json.dumps(all_local_links)
}
response = dogecloud_api(api_path, data, json_mode=True)
print(response)
data = {
'rtype': 'path',
'urls': 'https://file-teamspeak-download.lolicon.team/file/'
}
response = dogecloud_api(api_path, data, json_mode=True)
print(response)
else:
print("文件未更新无需预热CDN。")

View File

@@ -0,0 +1,23 @@
beautifulsoup4==4.12.3
bs4==0.0.2
certifi==2024.7.4
charset-normalizer==3.3.2
colorama==0.4.6
colorlog==6.8.2
hjson==3.1.0
idna==3.7
mcdreforged==2.13.1
packaging==24.1
parse==1.20.2
prompt_toolkit==3.0.47
psutil==6.0.0
py-cpuinfo==9.0.0
PySocks==1.7.1
requests==2.32.3
resolvelib==1.0.1
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
soupsieve==2.6
typing_extensions==4.12.2
urllib3==2.2.2
wcwidth==0.2.13