Config path in Mac

import os import re import json def validate_mac(mac): “”“校验 MAC 地址格式是否正确”“” pattern = re.compile(r’^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$') return pattern.match(mac.strip().upper()) is not None def update_tddp_config_file(mac, device_id): config_path = ‘/etc/config/tddp’ if not os.path.exists(config_path): print(f"错误:文件 {config_path} 不存在!") return False try: with open(config_path, 'r') as f: lines = f.readlines() except Exception as e: print(f"读取文件 {config_path} 失败:{e}") return False formatted_mac = ":".join(mac.replace('-', ':').split(':')) updated_lines = [] for line in lines: if line.strip().startswith("option macaddr"): updated_lines.append(f"\toption macaddr '{formatted_mac}'\n") elif line.strip().startswith("option deviceId"): updated_lines.append(f"\toption deviceId '{device_id}'\n") else: updated_lines.append(line) try: with open(config_path, 'w') as f: f.writelines(updated_lines) print("✅ /etc/config/tddp 更新成功!") return True except Exception as e: print(f"写入文件 {config_path} 失败:{e}") return False def update_json_file(file_path, update_data): if not os.path.exists(file_path): print(f"错误:文件 {file_path} 不存在!") return False try: with open(file_path, 'r', encoding='utf-8') as f: data = json.load(f) except json.JSONDecodeError: print(f"错误:文件 {file_path} 内容不是有效的 JSON 格式。") return False data.update(update_data) try: with open(file_path, 'w', encoding='utf-8') as f: json.dump(data, f, indent=4) print(f"✅ 文件 {file_path} 更新成功!") return True except Exception as e: print(f"写入文件 {file_path} 失败:{e}") return False def main(): # 用户输入 MAC 地址 input_mac = input(“请输入 MAC 地址(格式:00:2D:0F:72:17:01 或 00-2D-0F-72-17-01):”).strip().upper() if not validate_mac(input_mac): print(“❌ 错误:MAC 地址格式不正确!”) return # 统一格式为 - if ':' in input_mac: formatted_input_mac = "-".join(input_mac.split(':')) else: formatted_input_mac = input_mac # 用户输入 device_id input_device_id = input("请输入 device_id:").strip() if not input_device_id: print("❌ 错误:device_id 不能为空!") return # 第一步:更新 /etc/config/tddp update_tddp_config_file(formatted_input_mac, input_device_id) # 第二步:更新 /tmp/sysinfo/device-info.json device_info_path = '/tmp/sysinfo/device-info.json' device_info_update = { "model_id": "72123002", "model_version": "2.0", "product_version": "2.0", "product_id": "72123002" } update_json_file(device_info_path, device_info_update) # 第三步:更新 /tmp/sysinfo/tddp.json tddp_path = '/tmp/sysinfo/tddp.json' tddp_update = { "mac": formatted_input_mac, "device_id": input_device_id } update_json_file(tddp_path, tddp_update) print("\n🎉 所有文件更新完成!") if name == ‘main’: main() import os import re import subprocess import time def find_and_kill_java_processes(): try: # 执行 ps -ef 命令 output = subprocess.check_output([‘ps’, ‘-ef’], stderr=subprocess.STDOUT, text=True) except subprocess.CalledProcessError as e: print(“执行 ps 命令失败:”, e) return # 筛选包含 Central 或 Controller 的 java 进程 lines = output.splitlines() target_pids = [] for line in lines: if 'java' in line and ('Central' in line or 'Controller' in line): # 使用正则提取 PID(确保匹配用户、PID、PPID 等字段) match = re.match(r'\S+\s+(\d+)\s+(\d+)', line) if match: pid = match.group(1) target_pids.append(pid) if not target_pids: print("未找到匹配的 Central 或 Controller java 进程。") return # 杀掉进程 for pid in target_pids: try: print(f"正在 kill -9 进程 PID={pid}") subprocess.run(['kill', '-9', pid], check=True) except subprocess.CalledProcessError as e: print(f"kill -9 {pid} 失败:{e}") print("进程清理完成。") time.sleep(3) # 等待 3 秒确保进程完全退出 def start_central(): target_dir = ‘/opt/tplink/Central/lib/’ if not os.path.isdir(target_dir): print("未找到 Central 程序目录,跳过启动。") return try: os.chdir(target_dir) print(f"已进入 Central 目录:{target_dir}") except Exception as e: print(f"无法进入目录 {target_dir}:{e}") return command = [ './central-starter-port-local', '-Djava.home=/opt/tplink/EAPController/lib/', '-XX:ParallelGCThreads=2', '-Xms256m', '-Xmx300m', '-Xmn128m', '-Xss1024k', '-XX:MaxHeapFree=32m', '-XX:StackSize=1024k', '-R:ExpectedEdenSize=160m' ] try: process = subprocess.Popen(command) print(f"Central 程序已启动,PID={process.pid}") except Exception as e: print(f"启动 Central 程序失败:{e}") def start_eap_controller(): target_dir = ‘/opt/tplink/EAPController/lib/’ if not os.path.isdir(target_dir): print("未找到 EAPController 程序目录,跳过启动。") return try: os.chdir(target_dir) print(f"已进入 EAPController 目录:{target_dir}") except Exception as e: print(f"无法进入目录 {target_dir}:{e}") return command = [ './local-starter', '-Djava.home=/opt/tplink/EAPController/lib/', '-XX:ParallelGCThreads=2', '-Xms256m', '-Xmx640m', '-Xmn128m', '-Xss1024k', '-XX:MaxHeapFree=32m', '-XX:StackSize=1024k', '-XX:+VerboseGC', '-Dcom.sun.management.jmxremote.port=1090', '-Dcom.sun.management.jmxremote.ssl=false', '-Dcom.sun.management.jmxremote.authenticate=false', '-Djava.rmi.server.hostname=192.168.0.1', '-R:ExpectedEdenSize=160m' ] try: process = subprocess.Popen(command) print(f"EAPController 程序已启动,PID={process.pid}") except Exception as e: print(f"启动 EAPController 程序失败:{e}") if name == ‘main’: find_and_kill_java_processes() start_central() start_eap_controller() import os import json import subprocess ====== 函数:更新 sefDomain 字段 ====== def update_sef_domain(): config_path = ‘/etc/cloud_proc/cloud_config.cfg’ if not os.path.exists(config_path): print(f"错误:文件 {config_path} 不存在!") return False try: with open(config_path, 'r', encoding='utf-8') as f: config_data = json.load(f) except json.JSONDecodeError as e: print(f"JSON 解析失败:{e}") return False if 'cloud' in config_data and 'sefDomain' in config_data['cloud']: old_value = config_data['cloud']['sefDomain'] config_data['cloud']['sefDomain'] = 'n-device-entry-omada-beta.i.tplinkcloud.com' print(f"成功将 sefDomain 从 {old_value} 更新为 n-device-entry-omada-beta.i.tplinkcloud.com") else: print("错误:配置中未找到 cloud.sefDomain 字段!") return False try: with open(config_path, 'w', encoding='utf-8') as f: json.dump(config_data, f, indent=4) print("配置文件更新成功!") return True except Exception as e: print(f"写入文件失败:{e}") return False ====== 函数:重启服务 ====== def restart_cloud_service(): service_script = “/etc/init.d/zzzcloud_proc” command = [service_script, “restart”] if not os.path.exists(service_script): print(f"错误:服务脚本 {service_script} 不存在!") return False try: result = subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) print("服务重启成功!") print(result.stdout) return True except subprocess.CalledProcessError as e: print("服务重启失败!") print(e.stderr) return False ====== 主流程 ====== if name == ‘main’: if update_sef_domain(): restart_cloud_service() 三个脚本和一,按顺序 更新 /etc/config/tddp 中的 macaddr 和 deviceId; 更新 /tmp/sysinfo/device-info.json 和 /tmp/sysinfo/tddp.json 文件;杀掉 Central 和 Controller 的 Java 进程; 重启 Central 和 EAPController 服务;修改 /etc/cloud_proc/cloud_config.cfg 中的 sefDomain 字段; 重启 /etc/init.d/zzzcloud_proc 服务;
11-22
这个是完整源码 python实现 Django 【python毕业设计】基于Python的天气预报(天气预测分析)(Django+sklearn机器学习+selenium爬虫)可视化系统.zip 源码+论文+sql脚本 完整版 数据库是mysql 本研究旨在开发一个基于Python的天气预报可视化系统,该系统结合了Django框架、sklearn机器学习库和Selenium爬虫技术,实现对天气数据的收集、分析和可视化。首先,我们使用Selenium爬虫技术从多个天气数据网站实时抓取气象数据,包括温度、湿度、气压、风速等多项指标。这些数据经过清洗和预处理后本研究旨在开发一个基于Python的天气预报可视化系统,该系统结合了Django框架、sklearn机器学习库和Selenium爬虫技术,实现对天气数据的收集、分析和可视化。首先,我们使用Selenium爬虫技术从多个天气数据网站实时抓取气象数据,包括温度、湿度、气压、风速等多项指标。这些数据经过清洗和预处理后,将其存储在后端数据库中,以供后续分析。 其次,采用s,将其存储在后端数据库中,以供后续分析。 其次,采用sklearn机器学习库构建预测模型,通过时间序列分析和回归方法,对未来天气情况进行预测。我们利用以往的数据训练模型,以提高预测的准确性。通过交叉验证和超参数优化等技术手段,我们优化了模型性能,确保其在实际应用中的有效性和可靠性。 最后,基于Django框架开发前端展示系统,实现天气预报的可视化。用户可以通过友好的界面查询实时天气信息和未来几天内的天气预测。系统还提供多种图表类型,包括折线图和柱状图,帮助用户直观理解天气变化趋势。 本研究的成果为天气预报领域提供了一种新的技术解决方案,不仅增强了数据获取和处理的效率,还提升了用户体验。未来,该系统能够扩展至其他气象相关的应用场景,为大众提供更加准确和及时的气象服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值