Skip to content
  • #!/usr/bin/env python
    
    import subprocess
    
    r = subprocess.run("net 4e:4f:50", shell=True, capture_output=True)
    
    macs = []
    lines = r.stdout.split(b"\n")
    for line in lines:
        if b"4E:4F:50" in line:
            _, data = line.split(b"4E:4F:50")
            suffix = data.split(b" ")[0]
            macs.append(f"4E:4F:50{str(suffix, 'utf-8')}")
    
    for line in sorted(macs):
        print(line)
  • Improved version sorts by MAC address, but shows all net fields.

    #!/usr/bin/env python
    
    import subprocess
    
    r = subprocess.run("net 4e:4f:50", shell=True, capture_output=True)
    
    macs = {}
    lines = r.stdout.split(b"\n")
    for n, line in enumerate(lines):
        line = str(line, "utf-8")
        if n < 2:
            print(line)
        if "4E:4F:50" in line:
            _, data = line.split("4E:4F:50")
            suffix = data.split(" ")[0]
            mac = f"4E:4F:50{suffix}"
            entry = macs.get(mac, [])
            entry.append(line)
            macs[mac] = entry
    
    for mac in sorted(macs.keys()):
        lines = macs[mac]
        for line in lines:
                print(line)
    Edited by tfors
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment