写一个自动检测电脑配置脚本,并且能生成以电脑名称命名的配置表格,发给指定发给局域网内的共享主机的指定文件夹
时间: 2024-12-12 18:31:08 浏览: 2
为了编写一个自动检测电脑配置并生成配置表格的脚本,我们可以使用Python语言,因为它的简单易读性和丰富的库支持。我们将使用`psutil`库来获取系统信息,`pandas`来创建数据表格,以及`os`和`smtplib`来发送邮件。以下是简单的脚本示例:
```python
import psutil
import pandas as pd
import os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import smtplib
# 获取电脑配置信息
def get_system_info():
cpu_info = psutil.cpu_percent(interval=1)
memory_info = psutil.virtual_memory().percent
disk_info = psutil.disk_usage('/').percent
return {
'Computer Name': os.uname()[1],
'CPU Usage': cpu_info,
'Memory Usage': memory_info,
'Disk Usage': disk_info
}
# 创建配置表格
def create_config_table(info):
df = pd.DataFrame([info], columns=['Component', 'Value'])
config_df = df.set_index('Component')
return config_df
# 发送电子邮件
def send_email(config_table, recipient, shared_folder_path):
msg = MIMEMultipart()
msg['From'] = 'your_email@example.com'
msg['To'] = recipient
msg['Subject'] = f"Computer Configuration Report - {os.uname()[1]}"
body = "Please find below your computer's current configuration:\n\n"
body += config_table.to_string()
text = MIMEText(body, 'plain')
msg.attach(text)
with smtplib.SMTP('smtp.example.com', 587) as smtp:
smtp.starttls()
smtp.login(msg['From'], 'your_password')
smtp.send_message(msg)
smtp.quit()
# 主函数
def main():
system_info = get_system_info()
config_table = create_config_table(system_info)
share_folder = r'\\shared_host\config_files'
send_email(config_table, 'recipient_email@example.com', share_folder)
if __name__ == '__main__':
main()
```
在这个脚本中,你需要替换`your_email@example.com`, `your_password`, 和实际的SMTP服务器地址。
阅读全文