Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:31:04+00:00 2026-06-16T00:31:04+00:00

I have a subprocess executing: lshw -json -C network If i receive the following

  • 0

I have a subprocess executing:

lshw -json -C network

If i receive the following back:

    {
    "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"
    }
  },

Can i possibly iterate over this to ensure i capture all network interfaces (in the case that there’s more than one) which is not the case with my system.. Also, how can i pick 1 or two from this output, i don’t need the entire data.

I had the following in mind:

 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())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:31:05+00:00Added an answer on June 16, 2026 at 12:31 am

    Unfortunately, you cannot combine -C class filtering with -json output; even in the latest version JSON output is severely broken. Instead, filter the full JSON output yourself. Note that you should avoid using shell=True when using subprocess, pass in a list instead; no need to pipe stdin either, but do capture (silence) stderr.

    Then we can recurse over the ‘children’ structures, picking out anything that has a matching 'class' key:

    def get_nic_data():
        lshw_cmd = ['lshw', '-json']
        proc = subprocess.Popen(lshw_cmd, stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
        return proc.communicate()[0]
    
    def find_class(data, class_):
        for entry in data.get('children', []):
            if entry.get('class') == class_:
                yield entry
    
            for child in find_class(entry, class_):
                yield child
    
    def read_data(proc_output, class_='network'):
        import json
    
        for entry in find_class(json.loads(proc_output), class_):
            yield entry['vendor'], entry['description'], entry['product']
    

    then loop over read_data(get_nic_data()):

    for vendor, description, product in read_data(get_nic_data()):
        print vendor, description, product
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an instance of the Popen class created through subprocess.Popen. I would like
I have a subprocess function (called parseContents) that gets called using the following code:
I have the following Python lines: import subprocess subprocess.Popen(egrep -r --exclude=*{.git,.svn}* \text\ ~/directory, stdout=subprocess.PIPE,
I'm executing a SSH process like so: checkIn() sshproc = subprocess.Popen([command], shell=True) exit =
I have the following code in Python import subprocess import time info = subprocess.STARTUPINFO()
I have a problem with the following code: callBash.py: import subprocess print start subprocess.call(sleep.sh)
I have a line like the following: ping = subprocess.call('Fping.exe -H %s -L pingResults.txt
Here is what I have: process = subprocess.Popen([cmd.exe, /c appcfg.py, upload_data, --config_file=..\\bulkloader.yaml, --filename= +
I have the code: import subprocess , os ffmpeg = "C:\\ffmpeg_10_6_11.exe" inVid = "C:\\test_in.avi"
I have a python function that makes a subprocess call to a shell script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.