Skip to content

Instantly share code, notes, and snippets.

@opragel
Last active December 3, 2024 01:06
Show Gist options
  • Save opragel/59e368872303496db07061e67f0eb18f to your computer and use it in GitHub Desktop.
Save opragel/59e368872303496db07061e67f0eb18f to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
"""Intends to read USB SmartCard and return
device names, product IDs, and vendor IDs"""
import json
import subprocess
def main():
cmd = ['/usr/sbin/system_profiler', 'SPUSBDataType', '-json']
output = subprocess.check_output(cmd)
info = json.loads(output)
hardware_info = info['SPUSBDataType']
items = []
for dict in hardware_info:
if "_items" in dict:
for item in dict["_items"]:
items.append(f"{item['_name']},{item['product_id']}")
if not items:
items = "N/A"
print(f"<result>{items}</result>")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment