Skip to content

Forum in maintenance, we will back soon 🙂

Localhost Informati...
 
Notifications
Clear all

Localhost Information Script

2 Posts
2 Users
3 Reactions
251 Views
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
Topic starter
 

I've created a simple Python script to help with knowing information about your system in a tabular format.

You can find this project on GitHub.

File: .requirements.txt

psutil
tabulate

File: hostinfo.py

import platform
import os
import socket
import psutil
from tabulate import tabulate

# Function to get the local IP address
def get_local_ip():
    try:
        hostname = socket.gethostname()
        local_ip = socket.gethostbyname(hostname)
        return local_ip
    except Exception as e:
        return str(e)

# Function to get the external IP address
# This function uses a system command that might not work in all environments
def get_external_ip():
    try:
        external_ip = os.popen('curl -s  http://whatismyip.akamai.com /').read()
        return external_ip
    except Exception as e:
        return str(e)

# Collecting extensive information
info = {
    "Operating System": platform.system(),
    "OS Release": platform.release(),
    "Platform": platform.platform(),
    "Architecture": platform.architecture()[0],
    "Processor": platform.processor(),
    'Machine': platform.machine(),
    'Node': platform.node(),
    "CPU Cores": psutil.cpu_count(logical=False),
    "CPU Threads": psutil.cpu_count(logical=True),
    "Total RAM": f"{psutil.virtual_memory().total / (1024**3):.2f} GB",
    "Hostname": socket.gethostname(),
    "Local IP": get_local_ip(),
    "External IP": get_external_ip(),
    # Add more system details as needed
    "Python Version": platform.python_version(),
}

# Preparing for tabulate
data = [[key, value] for key, value in info.items()]

# Print in 2-column format
print(tabulate(data, headers=["Information", "Value"], tablefmt="grid"))

 

To use:

python3 -m venv .pyHostProbe
source .pyHostProbe/bin/activate
pip install -r .requirements.txt
python3 hostinfo.py

Sample output:

+------------------+--------------------------------------------------------+
| Information      | Value                                                  |
+==================+========================================================+
| Operating System | Linux                                                  |
+------------------+--------------------------------------------------------+
| OS Release       | 6.1.64-09049-g010fe86d9eae                             |
+------------------+--------------------------------------------------------+
| Platform         | Linux-6.1.64-09049-g010fe86d9eae-x86_64-with-glibc2.36 |
+------------------+--------------------------------------------------------+
| Architecture     | 64bit                                                  |
+------------------+--------------------------------------------------------+
| Processor        |                                                        |
+------------------+--------------------------------------------------------+
| Machine          | x86_64                                                 |
+------------------+--------------------------------------------------------+
| Node             | penguin                                                |
+------------------+--------------------------------------------------------+
| CPU Cores        | 4                                                      |
+------------------+--------------------------------------------------------+
| CPU Threads      | 4                                                      |
+------------------+--------------------------------------------------------+
| Total RAM        | 14.18 GB                                               |
+------------------+--------------------------------------------------------+
| Hostname         | penguin                                                |
+------------------+--------------------------------------------------------+
| Local IP         | 127.0.1.1                                              |
+------------------+--------------------------------------------------------+
| External IP      | 216.186.166.104                                        |
+------------------+--------------------------------------------------------+
| Python Version   | 3.11.2                                                 |
+------------------+--------------------------------------------------------+

Provide feedback: GitHub Issues

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 02/23/2024 4:31 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

Nice! You remind me, back in 2013, I was learning c# , I created a similar app with a UI 🙂

 
Posted : 02/24/2024 1:29 pm
Share:
[the_ad_group id="312"]