通过 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服务器硬件信息的更多相关文章

  1. Python 通过wmi获取Window服务器硬件信息

    通过pip install wmi安装wmi 查看cpu序列号: wmic cpu get processorid 查看主板序列号: wmic baseboard get serialnumber 查 ...

  2. 运用Python语言编写获取Linux基本系统信息(三):Python与数据库编程,把获取的信息存入数据库

    运用Python语言编写获取Linux基本系统信息(三):Python与数据库编程 有关前两篇的链接: 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本.内核.当前时间 运 ...

  3. 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本、内核、当前时间

    申请博客有一段时间了,然而到现在还一篇没有写过..... 主要因为没有想到需要写些什么,最近在学习Python语言,照着书上看了看最基础的东西,发现根本看不进去,而且光看的话今天看了觉得都理解懂了,过 ...

  4. 运用Python语言编写获取Linux基本系统信息(二):文件系统使用情况获取

    本文跟着上一篇文章继续写,上一篇文章的链接 运用Python语言编写获取Linux基本系统信息(一):获得Linux版本.内核.当前时间 一.随便说说 获取文件系统使用情况的思路和上一篇获取主要系统是 ...

  5. 使用 dmidecode 查看Linux服务器信息

    使用 dmidecode 查看Linux服务器信息 来源  http://www.laozuo.org/6682.html 对于大部分普通服务器用户来说,我们选择VPS.服务器产品的时候比较关心的是产 ...

  6. 使用 python 收集获取 Linux 系统主机信息

    使用 python 代码收集主机的系统信息,主要:主机名称.IP.系统版本.服务器厂商.型号.序列号.CPU信息.内存等系统信息. #!/usr/bin/env python #encoding: u ...

  7. 使用Python收集获取Linux系统主机信息

    爬虫代理IP由芝麻HTTP服务供应商提供 使用 python 代码收集主机的系统信息,主要:主机名称.IP.系统版本.服务器厂商.型号.序列号.CPU信息.内存等系统信息. #!/usr/bin/en ...

  8. 用Python获取Linux资源信息的三种方法

    方法一:psutil模块 #!usr/bin/env python # -*- coding: utf-8 -*- import socket import psutil class NodeReso ...

  9. 用python实现批量获取Linux主机简要信息并保存到Excel中 unstable 1.1

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- #filename get_linux_info.py #获取Linux主机的信息 # titles=[' ...

随机推荐

  1. Qt 静态库与共享库(动态库)共享配置的一个小办法

    对于用 QtCreator 编写静态库,动态库,如何能够以最小的改动, 方便的实现两种形式的库文件生成:可以这麽做: 1)使用想到建立静态库 2)在项目配置文件*.pro  中: TARGET = n ...

  2. [BZOJ4456][ZJOI2016]旅行者:分治+最短路

    分析 类似于点分治的思想,只统计经过分割线的最短路,然后把地图一分为二. 代码 #include <bits/stdc++.h> #define rin(i,a,b) for(regist ...

  3. Spring Cloud云服务架构 - commonservice-config配置服务搭建

    1. 介绍 Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持.使用Config Server,您可以在所有环境中管理应用程序的外部属性.客户端和服务器上的概念映射与 ...

  4. SQL语法——Join详解

    一.INNER JOIN 用法: select column_name(s) from table 1 INNER JOIN table 2 ON table 1.column_name=table ...

  5. fail-fast与fail-safe机制

    ----以下来自网址----- http://blog.csdn.net/ch717828/article/details/46892051 什么是 fail-fast 机制? fail-fast机制 ...

  6. Linux驱动开发8——中断处理

    中断包括软中断和硬中断两种,中断是一种异步I/O机制,即中断可以发生在任意时间点. 1.硬中断 硬件中断包括触发中断和处理中断两部分,而维系两者的是中断号,中断号是一种硬件资源. 1.1.注册和释放中 ...

  7. Collector解读以及自定义

    一.Collector接口解读: Collector接口解读: public interface Collector<T, A, R> { Supplier<A> suppli ...

  8. 【疑难杂症】Firefox 火狐浏览器 抓不到本地数据包

    日期:2019-05-17 23:28:11 介绍:火狐浏览器,如何才能够抓到本地(127.0.0.1)的数据包? 0x01.问题描述 在 Firefox 上安装了证书,浏览器也可以正常抓取互联网的 ...

  9. Unity—Compoent类

    官方API->Componment   新引入成员 作用 字段 gameobject 该组件所在的游戏对象 tag 游戏对象的标签 Transform 添加在游戏对象上的transform组件 ...

  10. 中国MOOC_零基础学Java语言_第5周 数组

    第5周 数组 5.1 数组 5.2 数组计算 public class Main { public static void main(String[] args) { for (int i = 1; ...