Skip to main content

Python script that collects various system details

 

  1. System information (OS, version, machine type, processor)

  2. Boot time

  3. CPU information (cores, frequencies)

  4. Memory usage

  5. Disk information (partitions, usage)

  6. Network information (hostname, IP, MAC address)

  7. Battery information (if available)

The script uses several Python libraries:

  • platform
    For system and OS information

  • psutil
    For hardware information (CPU, memory, disk, battery)

  • socket
    For network information

  • uuid
    For MAC address

  • datetime
    For formatting boot time

  • os
    For system operations

The script formats the output in readable way with section separators and proper indentation. The 

get_size()

 helper function converts bytes into human-readable formats (KB, MB, GB, etc.).

Note that some of these functions might require administrative/root privileges on certain systems, and some information might not be available on all platforms. The script includes basic error handling to prevent crashes in such cases.



import platform

import psutil

import socket

import uuid

import datetime

import os


def get_size(bytes, suffix="B"):

    """

    Scale bytes to its proper format

    """

    factor = 1024

    for unit in ["", "K", "M", "G", "T", "P"]:

        if bytes < factor:

            return f"{bytes:.2f}{unit}{suffix}"

        bytes /= factor


def get_system_info():

    print("="*40 + "System Information" + "="*40)

    

    # System information

    uname = platform.uname()

    print(f"System: {uname.system}")

    print(f"Node Name: {uname.node}")

    print(f"Release: {uname.release}")

    print(f"Version: {uname.version}")

    print(f"Machine: {uname.machine}")

    print(f"Processor: {uname.processor}")

    

    # Boot Time

    print("\n" + "="*40 + "Boot Time" + "="*40)

    boot_time_timestamp = psutil.boot_time()

    bt = datetime.datetime.fromtimestamp(boot_time_timestamp)

    print(f"Boot Time: {bt.year}/{bt.month}/{bt.day} {bt.hour}:{bt.minute}:{bt.second}")


    # CPU information

    print("\n" + "="*40 + "CPU Info" + "="*40)

    print("Physical cores:", psutil.cpu_count(logical=False))

    print("Total cores:", psutil.cpu_count(logical=True))

    

    # CPU frequencies

    cpufreq = psutil.cpu_freq()

    print(f"Max Frequency: {cpufreq.max:.2f}Mhz")

    print(f"Min Frequency: {cpufreq.min:.2f}Mhz")

    print(f"Current Frequency: {cpufreq.current:.2f}Mhz")

    

    # Memory Information

    print("\n" + "="*40 + "Memory Information" + "="*40)

    svmem = psutil.virtual_memory()

    print(f"Total: {get_size(svmem.total)}")

    print(f"Available: {get_size(svmem.available)}")

    print(f"Used: {get_size(svmem.used)}")

    print(f"Percentage: {svmem.percent}%")


    # Disk Information

    print("\n" + "="*40 + "Disk Information" + "="*40)

    partitions = psutil.disk_partitions()

    for partition in partitions:

        print(f"\nDrive: {partition.device}")

        print(f"  Mountpoint: {partition.mountpoint}")

        print(f"  File system type: {partition.fstype}")

        try:

            partition_usage = psutil.disk_usage(partition.mountpoint)

            print(f"  Total Size: {get_size(partition_usage.total)}")

            print(f"  Used: {get_size(partition_usage.used)}")

            print(f"  Free: {get_size(partition_usage.free)}")

            print(f"  Percentage: {partition_usage.percent}%")

        except Exception:

            continue


    # Network information

    print("\n" + "="*40 + "Network Information" + "="*40)

    print(f"Hostname: {socket.gethostname()}")

    print(f"IP Address: {socket.gethostbyname(socket.gethostname())}")

    print(f"MAC Address: {':'.join(('%012x' % uuid.getnode())[i:i+2] for i in range(0, 12, 2))}")


    # Battery information

    print("\n" + "="*40 + "Battery Information" + "="*40)

    battery = psutil.sensors_battery()

    if battery:

        print(f"Battery percentage: {battery.percent}%")

        print(f"Power plugged in: {battery.power_plugged}")

        minutes_left = battery.secsleft / 60

        if minutes_left > 0:

            print(f"Battery time left: {minutes_left:.2f} minutes")

    else:

        print("No battery detected")


if __name__ == "__main__":

    get_system_info()


Comments

Popular posts from this blog

Multi-Purpose Strainer or Washer Bowl for Rice Fruits & Vegetable Rice Bowl

 

Easy Bath Wet Wipes - Stay Fresh and Clean Anywhere, Anytime

Buy now in Amazon.in   Introducing Easy Bath Wet Wipes, your go-to solution for staying fresh and clean no matter where you are. These convenient and refreshing wipes are designed to provide a quick and effective way to freshen up, especially when you don't have access to water.   Why Choose Easy Bath Wet Wipes:   Instant Refreshment: Whether you're on the go, traveling, or in a situation where water isn't readily available, these wet wipes offer instant refreshment and cleanliness.   Large and Moist: Each wipe is generously sized and infused with just the right amount of moisture to ensure effective cleaning without excessive wetness.   Gentle on Skin: Formulated with gentle ingredients, these wipes are suitable for all skin types, including sensitive skin. They won't cause irritation or dryness.   Multipurpose: Use these wipes for a variety of purposes, including personal hygiene, cleaning...

Pups Kids Strong and Durable Plastic Chair with PVC Cushion Base - Comfort and Safety for Little Ones

Buy now in Amazon.in  Product priced at 233 Rs Introducing the Pups Kids Strong and Durable Plastic Chair with PVC Cushion Base – the perfect seating solution designed especially for your little ones. This kid-sized chair offers a delightful combination of comfort, safety, and durability, making it an essential addition to your child's space.   Why Choose the Pups Kids Plastic Chair:   Built to Last: Crafted from high-quality, sturdy plastic, this chair is designed to withstand the energetic playtime of active kids. It's built to last through countless adventures.   Safety First: We understand the importance of safety when it comes to children's furniture. That's why the Pups Kids Chair features rounded edges and a stable design to prevent tipping. Your child's safety is our priority.   Comfortable Seating: The chair comes with a soft PVC cushion base, providing a comfortable and cozy seating experience....