for partition in disk_partitions: print(f"Device: {partition.device}, Mount Point: {partition.mountpoint}")
# 获取磁盘使用情况 disk_usage = psutil.disk_usage('/') print(f"Total Disk Space: {disk_usage.total} bytes") print(f"Used Disk Space: {disk_usage.used} bytes") print(f"Free Disk Space: {disk_usage.free} bytes") print(f"Disk Usage Percentage: {disk_usage.percent}%")
获取网络信息:
1 2 3 4 5 6 7 8 9 10 11 12
# 获取网络接口信息 net_interfaces = psutil.net_if_addrs()
for interface, addresses in net_interfaces.items(): print(f"Interface: {interface}") for address in addresses: print(f" - Address Family: {address.family}, Address: {address.address}")
# 获取网络连接信息 net_connections = psutil.net_connections(kind='inet') for conn in net_connections: print(f"Local Address: {conn.laddr}, Remote Address: {conn.raddr}, Status: {conn.status}")