You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import subprocess
import hashlib
import os
import re
import requests
from bs4 import BeautifulSoup
import base64
from flask import Flask, request, jsonify
# 获取CPU序列号
def get_cpu_serial():
try:
cmd = 'wmic cpu get processorid'
result = subprocess.check_output(cmd, shell=True).decode()
return result.strip()
except subprocess.CalledProcessError as e:
return "Error: " + str(e)
# 根据CPU序列号生成授权码
def generate_authorization_code(cpu_serial):
# 添加一些随机生成的元素以增加复杂性
random_element = os.urandom(16) # 生成16字节的随机数
# 将CPU序列号和随机元素合并
combined_data = cpu_serial.encode() + random_element
# 使用SHA-256哈希算法
auth_code = hashlib.sha256(combined_data).hexdigest()
return auth_code
def extract_chinese_surnames():
# 调用函数并传入文件路径
file_path = 'db.txt' # 这里需要替换成你的文件实际路径
# 初始化一个空列表来存储中文姓氏
surnames = []
# 打开文件并读取每一行
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
# 使用正则表达式匹配中文字符
# \u4e00-\u9fff 表示匹配任何中文汉字的Unicode编码范围
surname = re.findall(r'[\u4e00-\u9fff]+', line)
# 如果找到中文字符,将其作为姓氏添加到列表中
if surname:
surnames.extend(surname)
return surnames
def getXingMing(xm):
if xm[0:2] in extract_chinese_surnames():
xs = xm[0:2] # 两个字的复姓
mz = xm[2:] # 后续部分是名字
else:
xs = xm[0] # 一个字的单姓
mz = xm[1:] # 后续部分是名字
# 目标网站的URL
url = "https://m.xingming.com/dafen/"
# 准备要发送的数据,通常为字典格式
data = {
'xs': xs,
'mz': mz,
'action': 'test'
}
# 发送POST请求
response = requests.post(url, data=data)
# 检查请求是否成功
if response.status_code == 200:
pass
else:
print("请求失败,状态码:", response.status_code)
return jsonify({'success': False, 'message': '请求失败'}), 201
# 打印响应内容
soup = BeautifulSoup(response.text, "html.parser")
# 详细信息
original_string = ''
for i in range(4, 35):
elements = soup.select("p")[i]
original_string = original_string + '<p>' + elements.text.replace('根据姓名网·名字测试打分,', '') + '</p>'
# 得分
score = soup.select("p")[34].select("font")[0].text
# 对字节进行URL安全的Base64编码
# 将字符串转换为字节
bytes_to_encode = original_string.encode('utf-8')
encoded_bytes_urlsafe = base64.urlsafe_b64encode(bytes_to_encode)
# 将URL安全的Base64编码后的字节对象解码为字符串
encoded_string_urlsafe = encoded_bytes_urlsafe.decode('utf-8')
return jsonify({'success': True, 'score': int(score), 'memo': encoded_string_urlsafe}, 200)
# 起名
def getQingMing(gsname, qimingsex): # 1男 0
# 目标网站的URL
url = "https://m.xingming.com/qiming/"
# 准备要发送的数据,通常为字典格式
data = {
'gsname': gsname,
'qimingsex': qimingsex,
'action': 'test'
}
# 发送POST请求
response = requests.post(url, data=data)
# 检查请求是否成功
if response.status_code == 200:
pass
else:
print("请求失败,状态码:", response.status_code)
return jsonify({'success': False, 'message': '请求失败'}), 201
# 打印响应内容
soup = BeautifulSoup(response.text, "html.parser")
names = []
for i in range(13, 25):
nName = soup.select("li")[i].next.text
names.append(nName)
return names