Get Machine Information using Python

PUPROSE

Extracting Information such as OS, RAM, Virtualization State, GPU from a Windows Machine.

Prerequisites

There are a couple of modules in Python that we will require to extract information about user's machine.

About the Libraries

subprocess

  • Simulate running commands in Windows Command Prompt
  • Run Powershell Commands for information that cannot be directly or reliably extracted using Python modules

Usage can be broken down into these steps:

  • Create a list filled with parameters that would be joined to form a command such as:

    os_info_cmd = ["powershell", "Get-WmiObject Win32_OperatingSystem | select Caption -ExpandProperty Caption"]

  • Pass the list to subprocess.Popen & Open a pipe to standard stream

    subprocess.Popen(os_info_cmd, stdout=subprocess.PIPE)

  • Decode the response and ignore errors

    decode('utf-8', 'ignore')

  • Use Split operation to extract the relevant portion of the output
  • Strip the output received

platform

  • Provides system level information
  • Provides access to underlying platform's identifying data

requests

  • HTTP for Humans
  • Make GET/POST/PUT/DELETE requests with ease

psutil

  • To get information about running processes
  • Get system utilization details such as CPU, memory, disk space, network usage etc.

wmi

  • WMI stands for Windows Mangement Instrumentation
  • wmi library is a wrapper for pywin32
  • Helps in managing devices and applications

ctypes

  • provides C Compatible data types for Python
  • Helps in calling functions from DLLs or shared libraries

locale

  • LOCALE is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language code and a country/region code.
  • Things like Case Convention, Number Formatting, Date-Time Formats etc. depend on user's locale
  • The locale module exposes POSIX locale database
  • It simplifies the process of developing an app or system that can be used by people with different cultural backgrounds and/or locations.

os

Provides OS independent utility functions such as:

  • listing files in a directory
  • changing/removing/adding directories
  • extracting file paths
  • joining paths
  • checking if a file exists

Extracting Machine Information

OS

CPU

GPU

RAM

LOCALE

IP

VIRTUALIZATION

DOT NET VERSION


Getting System Details

Note: If your OS is Windows, you can get GPU details like so:

Further, to get BIOS Virtualization info:

Thank the author. Fork this blog.


Tagged in windowspython