Skip to content

Instantly share code, notes, and snippets.

@ZakomakotheZBH
Created April 11, 2026 12:10
Show Gist options
  • Select an option

  • Save ZakomakotheZBH/4e8acbabdefc040377178870a7238b20 to your computer and use it in GitHub Desktop.

Select an option

Save ZakomakotheZBH/4e8acbabdefc040377178870a7238b20 to your computer and use it in GitHub Desktop.
A harmless c hardware viewer
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
void print_device_info(const char *path, const char *dev_node) {
char attr_path[512];
char buffer[256];
FILE *fp;
printf("--------------------------------------\n");
printf("Device ID: %s\n", dev_node);
// Get Product Name
snprintf(attr_path, sizeof(attr_path), "%s/%s/product", path, dev_node);
if ((fp = fopen(attr_path, "r"))) {
if (fgets(buffer, sizeof(buffer), fp)) printf("Product: %s", buffer);
fclose(fp);
}
// Get Manufacturer
snprintf(attr_path, sizeof(attr_path), "%s/%s/manufacturer", path, dev_node);
if ((fp = fopen(attr_path, "r"))) {
if (fgets(buffer, sizeof(buffer), fp)) printf("Manufacturer: %s", buffer);
fclose(fp);
}
// Get Serial Number
snprintf(attr_path, sizeof(attr_path), "%s/%s/serial", path, dev_node);
if ((fp = fopen(attr_path, "r"))) {
if (fgets(buffer, sizeof(buffer), fp)) printf("Serial: %s", buffer);
fclose(fp);
}
}
int main() {
const char *base_path = "/sys/bus/usb/devices";
struct dirent *entry;
DIR *dp = opendir(base_path);
if (dp == NULL) {
perror("Could not open /sys/bus/usb/devices. Ensure you are on a Linux-based system.");
return 1;
}
printf("ZTL Hardware Inventory Tool\n");
printf("Scanning for USB and External Devices...\n");
while ((entry = readdir(dp))) {
// Filter for main device nodes (usually contain ':' or start with 'usb')
if (entry->d_name[0] != '.') {
print_device_info(base_path, entry->d_name);
}
}
closedir(dp);
printf("--------------------------------------\n");
printf("Scan Complete.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment