Python 通过dmidecode获取Linux服务器硬件信息
通过 dmidecode 命令可以获取到 Linux 系统的包括 BIOS、 CPU、内存等系统的硬件信息,这里使用 python 代码来通过调用 dmidecode 命令来获取 Linux 必要的系统信息
用法:
1、 dmidecode -t [类型代码或名称 ] 指令
(1)获取系统信息,例如:
sudo dmidecode -t 1

(2)获取主板信息:
sudo dmidecode -t 2

(3)获取CPU ID
sudo dmidecode -t 4 | grep ID
(4)获取系统序列号
sudo dmidecode | grep Serial
附:
dmidecode -t 指令参数参考
Type Information
────────────────────────────────────────────
0 BIOS
1 System
2 Baseboard
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply
40 Additional Information
41 Onboard Devices Extended Information
42 Management Controller Host Interface
2、dmidecode -s [关键字] 指令
例如,查看处理器生产厂家:
sudo dmidecode -s processor-manufacturer
附可查询的关键字:
bios-vendor, bios-version, bios-release-date,
system-manufacturer, system-product-name,system-version, system-serial-number, system-uuid,
baseboard-manufacturer, baseboard-product-name, baseboard-version, baseboard-serial-number, baseboard-asset-tag,
chassis-manufacturer, chassis-type, chassis-version, chassis-serial-number, chassis-asset-tag,
processor-family, processor-manufacturer, processor-version, processor-frequency
需要配置sudo免密:请参照 https://gaoming.blog.csdn.net/article/details/88993044
通过Python获取cpu id、主办序列号、内存数量
#!/usr/bin/python
# encoding: utf-8
import subprocess
def getCpuId():
p = subprocess.Popen(["sudo dmidecode -t 4 | grep ID"], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE , stderr=subprocess.PIPE)
data = p.stdout
lines = []
while True:
line = str(data.readline(), encoding="utf-8")
if line == '\n':
break
if line:
d = dict([line.strip().split(': ')])
lines.append(d)
else:
break
return lines
def getBaseboardSerialnumber ():
p = subprocess.Popen(["sudo dmidecode -t 2 | grep Serial"], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE , stderr=subprocess.PIPE)
data = p.stdout
lines = []
while True:
line = str(data.readline(), encoding="utf-8")
if line == '\n':
break
if line:
d = dict([line.strip().split(': ')])
lines.append(d)
else:
break
return lines
def memory ():
p = subprocess.Popen(["sudo dmidecode -t memory | grep 'Number Of Devices'"], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE , stderr=subprocess.PIPE)
data = str(p.stdout.read(), encoding="utf-8")
d = dict([data.strip().split(': ')])
return d
if __name__ == '__main__':
print (getCpuId())
print (getBaseboardSerialnumber())
print (memory())

Python 通过dmidecode获取Linux服务器硬件信息的更多相关文章
- Python 通过wmi获取Window服务器硬件信息
通过pip install wmi安装wmi 查看cpu序列号: wmic cpu get processorid 查看主板序列号: wmic baseboard get serialnumber 查 ...
- 运用Python语言编写获取Linux基本系统信息(三):Python与数据库编程,把获取的信息存入数据库
运用Python语言编写获取Linux基本系统信息(三):Python与数据库编程 有关前两篇的链接: 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本.内核.当前时间 运 ...
- 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本、内核、当前时间
申请博客有一段时间了,然而到现在还一篇没有写过..... 主要因为没有想到需要写些什么,最近在学习Python语言,照着书上看了看最基础的东西,发现根本看不进去,而且光看的话今天看了觉得都理解懂了,过 ...
- 运用Python语言编写获取Linux基本系统信息(二):文件系统使用情况获取
本文跟着上一篇文章继续写,上一篇文章的链接 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本.内核.当前时间 一.随便说说 获取文件系统使用情况的思路和上一篇获取主要系统是 ...
- 使用 dmidecode 查看Linux服务器信息
使用 dmidecode 查看Linux服务器信息 来源 http://www.laozuo.org/6682.html 对于大部分普通服务器用户来说,我们选择VPS.服务器产品的时候比较关心的是产 ...
- 使用 python 收集获取 Linux 系统主机信息
使用 python 代码收集主机的系统信息,主要:主机名称.IP.系统版本.服务器厂商.型号.序列号.CPU信息.内存等系统信息. #!/usr/bin/env python #encoding: u ...
- 使用Python收集获取Linux系统主机信息
爬虫代理IP由芝麻HTTP服务供应商提供 使用 python 代码收集主机的系统信息,主要:主机名称.IP.系统版本.服务器厂商.型号.序列号.CPU信息.内存等系统信息. #!/usr/bin/en ...
- 用Python获取Linux资源信息的三种方法
方法一:psutil模块 #!usr/bin/env python # -*- coding: utf-8 -*- import socket import psutil class NodeReso ...
- 用python实现批量获取Linux主机简要信息并保存到Excel中 unstable 1.1
#!/usr/bin/env python3 # -*- coding: utf-8 -*- #filename get_linux_info.py #获取Linux主机的信息 # titles=[' ...
随机推荐
- java把含小数点的数字字符串转换为int类型
String num ="1.00"; int abc =Double.valueOf(num).intValue();//转换为Int类型
- B. Uniqueness
B. Uniqueness 给定一个序列,要求删除一段连续子段,满足删掉子段后每个元素唯一 求最小子段长度 枚举起点,二分子段长度 记得先sort 再unique #include<bits/s ...
- ASP.NET MVC3.0下载功能实现
C#代码: #region 下载文件 /// <summary> /// 下载文件 /// </summary> /// <param name="url&qu ...
- Linux系统设置开机自动启动ORACLE数据库服务
具体方法如下: 1. 修改oratab (root用户执行) /etc/oratab的配置格式如下: $ORACLE_SID:$ORACLE_HOME:Y 2. 测试dbstart, dbstop(o ...
- java中的过滤器 --Filter
package filter; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.Filter ...
- 《Effective Java》读书笔记 - 4.类和接口
Chapter 4 Classes and Interfaces Item 13: Minimize the accessibility of classes and members 一个好的模块设计 ...
- Spring各种类型数据的注入
直接上代码: 一个MessageBean类 package com.henu.spring; import java.util.*; public class MessageBean { privat ...
- libusb开发者指南
本文档描述libusb的API,以及如何开发USB应用.1 介绍 1.1 概览本文档描述libusb-0.1的API和USB相关内容.1.2 当前OS支持Linux 2.2或以上FreeBSD/N ...
- windows下mingw编译faac
进入目录先运行 ./bootstrap 接着就可以 ./configure --without-mp4v2 然后 make make install
- 移动Anaconda安装目录后导致图标变白以及Anaconda Navigator,Anaconda Prompt,jupyter notebook和spyder启动不了的解决方法
Q:因为移动了Anaconda3的安装目录,所以Anaconda3的相应应用程序启动不了,包括图标也会变白 解决方法:修改对应快捷键的属性,有对应的启动位置,修改下位置路径配置以及图标(Anacond ...