欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 服务器信息获取工具

服务器信息获取工具

2024/10/24 15:24:45 来源:https://blog.csdn.net/qq_39016353/article/details/140293341  浏览:    关键词:服务器信息获取工具
功能介绍
  • SSH连接到远程服务器:
  • 用户可以输入目标服务器的IP地址、用户名、密码以及SSH端口(默认22)。
  • 工具会尝试连接到远程服务器,并在连接失败时显示错误信息。
  • 运行命令并返回输出:
  • 工具可以在远程服务器上运行命令,并返回命令的输出结果。
  • 解析配置文件:
  • 工具可以解析不同类型的配置文件,包括PHP、Java、Python、Ruby和ASP/.NET,提取数据库配置信息。

4. 分析服务器信息:

  • 工具可以获取系统信息、用户信息、网络信息、进程信息和已安装的软件信息。
  • 工具还可以获取网站配置和数据库配置信息。

5. 保存结果到文件:

  • 用户可以选择保存路径,工具会将分析结果保存为JSON文件。

SSH连接实现

import paramiko
from tkinter import messageboxdef ssh_connect(ip, username, password, port=22):try:client = paramiko.SSHClient()client.set_missing_host_key_policy(paramiko.AutoAddPolicy())client.connect(ip, username=username, password=password, port=port)return clientexcept Exception as e:messagebox.showerror("连接失败", f"连接失败: {e}")return None
运行命令并返回输出
def run_command(client, command):stdin, stdout, stderr = client.exec_command(command)return stdout.read().decode()

服务器基本信息

def analyze_server(client):results = {}# 系统信息os_version = run_command(client, "cat /etc/os-release")kernel_version = run_command(client, "uname -r")hostname = run_command(client, "hostname")results['系统信息'] = {'os_version': os_version.strip().split('\n'),'kernel_version': kernel_version.strip(),'hostname': hostname.strip()}# 用户信息users = run_command(client, "cat /etc/passwd")sudoers = run_command(client, "cat /etc/sudoers")results['用户信息'] = {'users': users.strip().split('\n'),'sudoers': sudoers.strip().split('\n')}# 网络信息interfaces = run_command(client, "ip addr")ifconfig = run_command(client, "ifconfig")listening_ports = run_command(client, "netstat -anp")active_connections = run_command(client, "ss -tunap")results['网络信息'] = {'interfaces': interfaces.strip().split('\n'),'ifconfig': ifconfig.strip().split('\n'),'listening_ports': listening_ports.strip().split('\n'),'active_connections': active_connections.strip().split('\n')}# 进程信息processes = run_command(client, "ps aux")results['进程信息'] = processes.strip().split('\n')# 已安装的软件installed_software = run_command(client, "rpm -qa")results['安装软件信息'] = installed_software.strip().split('\n')return results

主界面效果

输出内容

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com