lshw
.netなどのハードウェアデータを照会するために複数のUNIXユーティリティを使用する.netコアアプリケーションがありますiwlist
。出力がサポートされているため問題ありません。私は現在私自身の構文解析コードを書いていますが、そのようなツールの出力を解析できるツールがないことに驚きました。dmidecode
lshw
json
私は正しいですか?
答え1
TxR緩く構造化された複数行のテキストから情報を抽出する言語。
出力を例としてdmidecode
JSONオブジェクトのリストに変換してみましょう。
$ txr dmi-data.txr dmi-data
{"Version":"VirtualBox","Address":"0xE0000","Characteristics":["ISA is supported","PCI is supported","Boot from CD is supported",
"Selectable boot is supported","8042 keyboard services are supported (int 9h)",
"CGA/mono video services are supported (int 10h)","ACPI is supported"],
"desc":"BIOS Information","Vendor":"innotek GmbH","ROM Size":"128 kB",
"Release Date":"12/01/2006","Runtime Size":"128 kB"}
{"Version":"1.2","Wake-up Type":"Power Switch","desc":"System Information",
"SKU Number":"Not Specified","Manufacturer":"innotek GmbH","Serial Number":"0",
"Product Name":"VirtualBox","Family":"Virtual Machine","UUID":"CE1C8E2B-F6C0-4E0B-9E40-7958B29D121F"}
{"Version":"1.2","desc":"Base Board Information","Features":["Board is a hosting board"],
"Type":"Motherboard","Chassis Handle":"0x0003","Contained Object Handles":"0",
"Manufacturer":"Oracle Corporation","Serial Number":"0","Asset Tag":"Not Specified",
"Product Name":"VirtualBox","Location In Chassis":"Not Specified"}
{"Version":"Not Specified","desc":"Chassis Information","Boot-up State":"Safe",
"Type":"Other","Security Status":"None","Manufacturer":"Oracle Corporation",
"Lock":"Not Present","Serial Number":"Not Specified","Thermal State":"Safe",
"Asset Tag":"Not Specified","Power Supply State":"Safe"}
{"desc":"OEM Strings","String 2":"vboxRev_140239","String 1":"vboxVer_6.1.14"}
{"desc":"OEM-specific Type","Header and Data":["80 08 08 00 2B C3 33 00"]}
プログラムは次のとおりです。
# dmidecode @nil
@(skip)
Table at @nil
@(collect :vars (obj))
Handle @nil
@desc
@ (require (not (mequal desc "Inactive" "End Of Table")))
@ (bind obj @(hash))
@ (repeat :gap 0)
@ (cases)
@\t@prop: @value
@ (do (set [obj prop] value))
@ (or)
@\t@prop:
@ (collect :gap 0)
@\t@\t@valueline
@ (end)
@ (do (set [obj prop] (vec-list valueline)))
@ (end)
@ (until)
Handle @nil
@ (end)
@ (do (set [obj "desc"] desc))
@(end)
@(do (put-jsons obj))
このdmi-data
ファイルには以下が含まれます。
# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.
10 structures occupying 450 bytes.
Table at 0x000E1000.
Handle 0x0000, DMI type 0, 20 bytes
BIOS Information
Vendor: innotek GmbH
Version: VirtualBox
Release Date: 12/01/2006
Address: 0xE0000
Runtime Size: 128 kB
ROM Size: 128 kB
Characteristics:
ISA is supported
PCI is supported
Boot from CD is supported
Selectable boot is supported
8042 keyboard services are supported (int 9h)
CGA/mono video services are supported (int 10h)
ACPI is supported
Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: innotek GmbH
Product Name: VirtualBox
Version: 1.2
Serial Number: 0
UUID: CE1C8E2B-F6C0-4E0B-9E40-7958B29D121F
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Virtual Machine
Handle 0x0008, DMI type 2, 15 bytes
Base Board Information
Manufacturer: Oracle Corporation
Product Name: VirtualBox
Version: 1.2
Serial Number: 0
Asset Tag: Not Specified
Features:
Board is a hosting board
Location In Chassis: Not Specified
Chassis Handle: 0x0003
Type: Motherboard
Contained Object Handles: 0
Handle 0x0003, DMI type 3, 13 bytes
Chassis Information
Manufacturer: Oracle Corporation
Type: Other
Lock: Not Present
Version: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: None
Handle 0x0007, DMI type 126, 42 bytes
Inactive
Handle 0x0005, DMI type 126, 15 bytes
Inactive
Handle 0x0006, DMI type 126, 28 bytes
Inactive
Handle 0x0002, DMI type 11, 7 bytes
OEM Strings
String 1: vboxVer_6.1.14
String 2: vboxRev_140239
Handle 0x0008, DMI type 128, 8 bytes
OEM-specific Type
Header and Data:
80 08 08 00 2B C3 33 00
Handle 0xFEFF, DMI type 127, 4 bytes
End Of Table