Linux程序获取硬件信息HardWareLiSter源码修改适配
又见到你(解压后直接make,然后进⼊src/⽬录执⾏./lshw获取电脑的硬件信息包括内存,主板,CPU,硬件,⽹卡,显卡,声卡等等信息)
源码编译后执⾏lshw和命令lshw结果是⼀样的
lshw命令如下(看得到信息⾮常详细但是对于不同的需求来说要求是不⼀样的,这些信息已经有些冗余了对我来说):
deepin@deepin-PC:~/$ lshw
WARNING: you should run this program as super-ur.
deepin-pc
description: Computer
product: N/A
version: Talas Talas 0 Talas Talas 0 Talas Talas 0 Talas Talas 0
width:64 bits
capabilities: smp
*-core
description: Motherboard
physical id:0
*-memory
description: System memory
physical id:0
size:7524MiB
*-cpu:0
product: Sunway
vendor: Jiangnan Computer Technology Rearch Institute
physical id:1
bus info: cpu@0
version: SW6A
width:64 bits
capabilities: bwx fix cix mvi pat pmi
*-cpu:1 DISABLED
product: Sunway
vendor: Jiangnan Computer Technology Rearch Institute
physical id:2
bus info: cpu@1
version: SW6A
width:64 bits
capabilities: bwx fix cix mvi pat pmi
*-cpu:2 DISABLED
product: Sunway
vendor: Jiangnan Computer Technology Rearch Institute
physical id:3
bus info: cpu@2
version: SW6A
width:64 bits
capabilities: bwx fix cix mvi pat pmi
*-cpu:3 DISABLED
product: Sunway
vendor: Jiangnan Computer Technology Rearch Institute
physical id:4
bus info: cpu@3
version: SW6A
width:64 bits
capabilities: bwx fix cix mvi pat pmi
*-pci
description: PCI bridge
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:100
bus info: pci@0000:01:00.0
version: ca
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
resources: memory:c0e0600000-c0e063ffff ioport:c600001000(size=8192) memory:c0e0000000-c0e05fffff ioport:c3c0000000(size=8388608)
resources: memory:c0e0600000-c0e063ffff ioport:c600001000(size=8192) memory:c0e0000000-c0e05fffff ioport:c3c0000000(size=8388608) *-pci:0
description: PCI bridge
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:1
bus info: pci@0000:02:01.0
version: ca
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
resources: ioport:c600001000(size=4096) memory:c0e0000000-c0e02fffff ioport:c3c0000000(size=2097152)
*-sata
description: SATA controller
product: ASM1062 Serial ATA Controller
vendor: ASMedia Technology Inc.
physical id:0
bus info: pci@0000:03:00.0
习惯英文version:02
width:32 bits
clock:33MHz
capabilities: sata ahci_1.0 bus_master cap_list rom
configuration: driver=ahci latency=0
resources: irq:21 ioport:c600001020(size=8) ioport:c600001030(size=4) ioport:c600001028(size=8) ioport:c600001034(size=4) ioport:c6000010 00(size=32) memory:c0e0010000-c0e00101ff memory:c0e0000000-c0e000ffff
*-pci:1
description: PCI bridge
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:2
bus info: pci@0000:02:02.0
version: ca
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
*-pci:2
description: PCI bridge
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:8
bus info: pci@0000:02:08.0
version: ca
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
resources: ioport:c3c0200000(size=1048576)
*-usb
description: USB controller
product: EJ188/EJ198 USB 3.0 Host Controller
vendor: Etron Technology, Inc.
physical id:0
bus info: pci@0000:05:00.0
version:00
width:64 bits
clock:33MHz
capabilities: xhci bus_master cap_list
configuration: driver=xhci_hcd latency=0
resources: iomemory:30-2f irq:27 memory:c3c0200000-c3c0207fff
*-pci:3
description: PCI bridge
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:9
bus info: pci@0000:02:09.0
version: ca
width:32 bits
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
resources: ioport:c600002000(size=4096) memory:c0e0300000-c0e05fffff ioport:c3c0300000(size=2097152)
*-network
description: Ethernet interface
product: I210 Gigabit Network Connection
vendor: Intel Corporation
physical id:0
bus info: pci@0000:06:00.0
logical name: enp6s0
version:03
rial:00:0b:2f:18:50:3d
size:100Mbit/s
capacity:1Gbit/s
width:32 bits
昆虫记好段
clock:33MHz
capabilities: bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=igb driverversion=5.4.0-k duplex=full firmware=3.25,0x800005cf ip=192.168.6.48 latenc y=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s
resources: irq:17 memory:c0e0300000-c0e037ffff ioport:c600002000(size=32) memory:c0e0380000-c0e0383fff *-pci:4
description: PCI bridge
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:10
bus info: pci@0000:02:10.0
version: ca
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
resources: ioport:c3c0500000(size=1048576)
*-usb
description: USB controller
product: EJ188/EJ198 USB 3.0 Host Controller
vendor: Etron Technology, Inc.
physical id:0
bus info: pci@0000:07:00.0
version:00
width:64 bits
clock:33MHz
capabilities: xhci bus_master cap_list
configuration: driver=xhci_hcd latency=0
resources: iomemory:30-2f irq:28 memory:c3c0500000-c3c0507fff
*-pci:5
description: PCI bridge
网球比分
product: PEX 874848-Lane,12-Port PCI Express Gen 3(8 GT/s) Switch,27 x 27mm FCBGA
vendor: PLX Technology, Inc.
physical id:11
bus info: pci@0000:02:11.0
version: ca
width:32 bits
clock:33MHz
capabilities: pci normal_decode bus_master cap_list
*-display
description: VGA compatible controller
product: Oland [Radeon HD 8570/ R7 240/340/ R520 OEM]
vendor: Advanced Micro Devices, Inc.[AMD/ATI]
physical id:5
bus info: pci@0001:20:00.0
version:87
width:64 bits妇人家
clock:33MHz
capabilities: vga_controller bus_master cap_list rom
configuration: driver=radeon latency=0
resources: iomemory:30-2f iomemory:30-2f irq:281 memory:f3c0000000-f3cfffffff memory:f3d0000000-f3d003ffff ioport:f600001000(size=256) mem
resources: iomemory:30-2f iomemory:30-2f irq:281 memory:f3c0000000-f3cfffffff memory:f3d0000000-f3d003ffff ioport:f600001000(size=256) mem ory:f0e0000000-f0e001ffff
*-multimedia UNCLAIMED
description: Audio device
product: Oland/Hainan/Cape Verde/Pitcairn HDMI Audio [Radeon HD 7000 Series]
vendor: Advanced Micro Devices, Inc.[AMD/ATI]
physical id:0.1
bus info: pci@0001:20:00.1
version:00
width:64 bits
clock:33MHz
capabilities: cap_list
configuration: latency=0
resources: iomemory:30-2f memory:f3d0040000-f3d0043fff
WARNING: output may be incomplete or inaccurate, you should run this program as super-ur.
以下是源码修改后(print中的输出函数Myprint_修改),不同的需求修改的也不⼀样,⼤家根据需求⾃⼰阅读源码⾃⾏修改
print⽂件
//新增函数
void GetInfo(hwNode & node,string &buf,string id)
{
//cpu 只取⼀条
if(id =="cpu")
{
if(!Product().empty())
{
buf +=string("cpu处理器")+"=";
buf += Product();
buf +=string("\n");
return;
}
}
//其他取三条
Description()!="")
{
buf += Description();
}
Product()!="")
{
buf +=string(",")+ Product();
}
Vendor()!="")
{
buf +=string(",")+ Vendor();
}
//内存或硬盘获取⼤⼩
if(id =="memory"|| id =="disk")
{
Size()>0)
{
Class())
{
ca hw::disk:
buf +=string(",")+Size())+"B";
break;
ca hw::display:
ca hw::memory:
ca hw::address:
ca hw::storage:
ca hw::volume:
buf +=string(",")+Size());
break;
毛里求斯签证ca hw::processor:
ca hw::processor:
ca hw::bus:
ca hw::system:
ca hw::network:
ca hw::power:
break;
default:
break;幼小衔接活动方案
}
}
}
buf +=string("\n");
}
//修改原有输出函数
void Myprint_(hwNode & node,string &buf,bool html,int level) {
if(ClassName()))
{
Id()=="core")
{
buf +=string("主板信息")+"=";
GetInfo(node,buf,"core");
}
el Id()=="firmware")
{
buf +=string("BIOS")+"=";
GetInfo(node,buf,"firmware");
}
el Id()=="ide")
{
buf +=string("IDE ATA/ATAPI控制器")+"=";
GetInfo(node,buf,"ide");
结业报告
}
el Id()=="display")
{
buf +=string("显卡")+"=";
GetInfo(node,buf,"display");
}
el Id()=="network")
{
buf +=string("⽹卡")+"=";
GetInfo(node,buf,"network");
}
el Id()=="multimedia")
{
buf +=string("声卡")+"=";
GetInfo(node,buf,"multimedia");
}
el Id()=="cdrom")
{
buf +=string("光驱")+"=";
GetInfo(node,buf,"cdrom");
}
el Id().find("cpu")!= std::string::npos)
{
//cpu 处理⼀次
if(buf.find("cpu处理器")== std::string::npos)
{
GetInfo(node,buf,"cpu");
}
}
el Id()=="memory")
{
buf +=string("内存")+"=";
GetInfo(node,buf,"memory");