サブプロセスを実行しています:
lshw -json -C network
次の返信を受け取った場合:
{
"id" : "network",
"class" : "network",
"claimed" : true,
"handle" : "PCI:0000:00:05.0",
"description" : "Ethernet interface",
"product" : "82545EM Gigabit Ethernet Controller (Copper)",
"vendor" : "Intel Corporation",
"physid" : "5",
"businfo" : "pci@0000:00:05.0",
"logicalname" : "eth0",
"version" : "00",
"serial" : "00:8c:42:77:58:49",
"units" : "bit/s",
"size" : 1000000000,
"capacity" : 1000000000,
"width" : 32,
"clock" : 66000000,
"configuration" : {
"autonegotiation" : "on",
"broadcast" : "yes",
"driver" : "e1000",
"driverversion" : "7.3.21-k8-NAPI",
"duplex" : "full",
"firmware" : "N/A",
"ip" : "10.211.55.10",
"latency" : "0",
"link" : "yes",
"multicast" : "yes",
"port" : "twisted pair",
"speed" : "1Gbit/s"
},
"capabilities" : {
"msi" : "Message Signalled Interrupts",
"bus_master" : "bus mastering",
"cap_list" : "PCI capabilities listing",
"ethernet" : true,
"physical" : "Physical interface",
"logical" : "Logical interface",
"tp" : "twisted pair",
"10bt" : "10Mbit/s",
"10bt-fd" : "10Mbit/s (full duplex)",
"100bt" : "100Mbit/s",
"100bt-fd" : "100Mbit/s (full duplex)",
"1000bt-fd" : "1Gbit/s (full duplex)",
"autonegotiation" : "Auto-negotiation"
}
},
私のシステムには当てはまらない、すべてのネットワークインターフェイス(複数ある場合)を確実にキャプチャするために、これを繰り返すことはできますか?また、この出力から1つまたは2つを選択するにはどうすればよいですか?データ全体が必要です。
私は次のことを念頭に置いていました。
def get_nic_data():
lshw_cmd = "lshw -json -C network"
proc = subprocess.Popen(lshw_cmd, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
return proc.stdout
def read_data(proc_output):
import simplejason as json
json_obj = json
json_obj.loads(proc_output)
#Obtain Vendor,Description,Product
#...
#...
json_obj.dumps(obtained_data_here)
#Not sure if this would work this way.
read_data(get_nic_data())