Last active
March 11, 2025 22:13
-
-
Save reddgr/87387d917738d7d6ec609fb536b88908 to your computer and use it in GitHub Desktop.
Jupyter Notebook for quickly checking system hardware and specs on any system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import psutil\n", | |
"from dotenv import load_dotenv\n", | |
"import os\n", | |
"import platform" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## General info" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"System: Linux\n", | |
"Node Name: bcn15-desktop\n", | |
"Release: 5.15.0-134-generic\n", | |
"Version: #145~20.04.1-Ubuntu SMP Mon Feb 17 13:27:16 UTC 2025\n", | |
"Machine: x86_64\n", | |
"Processor: x86_64\n" | |
] | |
} | |
], | |
"source": [ | |
"system_info = platform.uname()\n", | |
"print(f\"System: {system_info.system}\")\n", | |
"print(f\"Node Name: {system_info.node}\")\n", | |
"print(f\"Release: {system_info.release}\")\n", | |
"print(f\"Version: {system_info.version}\")\n", | |
"print(f\"Machine: {system_info.machine}\")\n", | |
"print(f\"Processor: {system_info.processor}\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Check Motherboard\n", | |
"\n", | |
"In this section, the password is retrieved from a `.env` file using the `dotenv` library. This password is then used to execute a system command that requires elevated privileges. The command `dmidecode -t 2` is run to provide detailed information about the motherboard." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"*****\n", | |
"[sudo] password for david: # dmidecode 3.2\n", | |
"Getting SMBIOS data from sysfs.\n", | |
"SMBIOS 2.6 present.\n", | |
"\n", | |
"Handle 0x0002, DMI type 2, 15 bytes\n", | |
"Base Board Information\n", | |
"\tManufacturer: Dell Inc.\n", | |
"\tProduct Name: 0K83V0\n", | |
"\tVersion: A00 \n", | |
"\tSerial Number: ..CN7509304K013A. \n", | |
"\tAsset Tag: \n", | |
"\tFeatures:\n", | |
"\t\tBoard is a hosting board\n", | |
"\t\tBoard is replaceable\n", | |
"\tLocation In Chassis: To Be Filled By O.E.M.\n", | |
"\tChassis Handle: 0x0003\n", | |
"\tType: Motherboard\n", | |
"\tContained Object Handles: 0\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"system_info = platform.uname()\n", | |
"if system_info.system=='Windows':\n", | |
" import wmi\n", | |
" c = wmi.WMI()\n", | |
" board = c.Win32_BaseBoard()[0]\n", | |
" print(\"Motherboard Information:\")\n", | |
" print(f\"Manufacturer: {board.Manufacturer}\")\n", | |
" print(f\"Product: {board.Product}\")\n", | |
" print(f\"Serial Number: {board.SerialNumber}\")\n", | |
" print(f\"Version: {board.Version}\")\n", | |
"\n", | |
"\n", | |
"else:\n", | |
" dotenv_path = \"../../../apis/.env\"\n", | |
" load_dotenv(dotenv_path)\n", | |
" password = os.getenv(\"UBUNTU_PWD\")\n", | |
"\n", | |
" def mask_token(token, unmasked_chars=0):\n", | |
" if unmasked_chars == 0:\n", | |
" return '*' * len(token)\n", | |
" return token[:unmasked_chars] + '*' * (len(token) - unmasked_chars*2) + token[-unmasked_chars:]\n", | |
"\n", | |
" print(mask_token(password, 0))\n", | |
"\n", | |
" command = 'dmidecode -t 2'\n", | |
" !echo {password}|sudo -S {command}" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Hardware stats" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This cell provides a summary of the system's hardware and usage statistics, including:\n", | |
"\n", | |
"- **CPU Model:** The model of the CPU installed in the system.\n", | |
"- **CPU Count:** The number of CPU cores available.\n", | |
"- **CPU Frequency:** The current operating frequency of the CPU.\n", | |
"- **CPU Usage:** The current CPU usage as a percentage.\n", | |
"\n", | |
"- **RAM Model:** The total amount of RAM installed in the system.\n", | |
"- **Total Memory:** The total memory available in the system.\n", | |
"- **Available Memory:** The amount of memory currently available for use.\n", | |
"- **Used Memory:** The amount of memory currently in use.\n", | |
"- **Memory Usage:** The current memory usage as a percentage." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"CPU Model: Intel(R) Core(TM)2 Quad CPU Q8300 @ 2.50GHz\n", | |
"RAM Model: 3970068 kB\n", | |
"CPU Count: 4\n", | |
"CPU Frequency: 2495.04225 MHz\n", | |
"CPU Usage: 34.5%\n", | |
"Total Memory: 3.79 GB\n", | |
"Available Memory: 0.91 GB\n", | |
"Used Memory: 2.46 GB\n", | |
"Memory Usage: 76.0%\n" | |
] | |
} | |
], | |
"source": [ | |
"system_info = platform.uname()\n", | |
"if system_info.system=='Windows':\n", | |
" import wmi\n", | |
" c = wmi.WMI()\n", | |
" # CPU model using WMI\n", | |
" processor = c.Win32_Processor()[0]\n", | |
" cpu_model = processor.Name\n", | |
"\n", | |
" print(f\"CPU Model: {cpu_model}\")\n", | |
"\n", | |
" # RAM model using WMI\n", | |
" memory = c.Win32_PhysicalMemory()[0]\n", | |
" ram_model = f\"{memory.Manufacturer} {memory.PartNumber}\"\n", | |
"\n", | |
" print(f\"RAM Model: {ram_model}\")\n", | |
"\n", | |
" # CPU details using psutil\n", | |
" cpu_count = psutil.cpu_count(logical=True)\n", | |
" cpu_freq = psutil.cpu_freq()\n", | |
" cpu_percent = psutil.cpu_percent(interval=1)\n", | |
"\n", | |
" print(f\"CPU Count: {cpu_count}\")\n", | |
" print(f\"CPU Frequency: {cpu_freq.current:.2f} MHz\")\n", | |
" print(f\"CPU Usage: {cpu_percent}%\")\n", | |
"\n", | |
" # RAM details using psutil\n", | |
" virtual_mem = psutil.virtual_memory()\n", | |
" total_mem = virtual_mem.total / (1024 ** 3) # Convert bytes to GB\n", | |
" available_mem = virtual_mem.available / (1024 ** 3) # Convert bytes to GB\n", | |
" used_mem = virtual_mem.used / (1024 ** 3) # Convert bytes to GB\n", | |
" memory_percent = virtual_mem.percent\n", | |
"\n", | |
" print(f\"Total Memory: {total_mem:.2f} GB\")\n", | |
" print(f\"Available Memory: {available_mem:.2f} GB\")\n", | |
" print(f\"Used Memory: {used_mem:.2f} GB\")\n", | |
" print(f\"Memory Usage: {memory_percent}%\")\n", | |
"\n", | |
"else: \n", | |
" # CPU model\n", | |
" cpu_model = \"\"\n", | |
" with open(\"/proc/cpuinfo\") as f:\n", | |
" for line in f:\n", | |
" if \"model name\" in line:\n", | |
" cpu_model = line.split(\":\")[1].strip()\n", | |
" break\n", | |
"\n", | |
" print(f\"CPU Model: {cpu_model}\")\n", | |
"\n", | |
" # RAM model\n", | |
" ram_model = \"\"\n", | |
" with open(\"/proc/meminfo\") as f:\n", | |
" for line in f:\n", | |
" if \"MemTotal\" in line:\n", | |
" ram_model = line.split(\":\")[1].strip()\n", | |
" break\n", | |
"\n", | |
" print(f\"RAM Model: {ram_model}\")\n", | |
"\n", | |
" # CPU details\n", | |
" cpu_count = psutil.cpu_count(logical=True)\n", | |
" cpu_freq = psutil.cpu_freq()\n", | |
" cpu_percent = psutil.cpu_percent(interval=1)\n", | |
"\n", | |
" print(f\"CPU Count: {cpu_count}\")\n", | |
" print(f\"CPU Frequency: {cpu_freq.current} MHz\")\n", | |
" print(f\"CPU Usage: {cpu_percent}%\")\n", | |
"\n", | |
" # RAM details\n", | |
" virtual_mem = psutil.virtual_memory()\n", | |
" total_mem = virtual_mem.total / (1024 ** 3) # Convert bytes to GB\n", | |
" available_mem = virtual_mem.available / (1024 ** 3) # Convert bytes to GB\n", | |
" used_mem = virtual_mem.used / (1024 ** 3) # Convert bytes to GB\n", | |
" memory_percent = virtual_mem.percent\n", | |
"\n", | |
" print(f\"Total Memory: {total_mem:.2f} GB\")\n", | |
" print(f\"Available Memory: {available_mem:.2f} GB\")\n", | |
" print(f\"Used Memory: {used_mem:.2f} GB\")\n", | |
" print(f\"Memory Usage: {memory_percent}%\")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment