Skip to content

Instantly share code, notes, and snippets.

Last active September 28, 2021 15:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ThomasG77/12c85e5e65b7776fd6d86bf9cb00a1bc to your computer and use it in GitHub Desktop.
import json
import os
import platform
import re
import socket
import uuid
from pprint import pprint as pp
import distro
from hurry.filesize import size
import psutil
# Need pip install distro psutil hurry.filesize
distro_name, distro_version, distro_codename = distro.linux_distribution()
partitions = psutil.disk_partitions()
disk_usage = []
for p in partitions:
usage = psutil.disk_usage(p.mountpoint)
'mountpoint': p.mountpoint,
'total': size(int(,
'used': size(int(usage.used))
config_content = {
"platform_release": platform.release(),
"platform_version": platform.version(),
"architecture": platform.machine(),
"hostname": socket.gethostname(),
"ip_address": socket.gethostbyname(socket.gethostname()),
"mac_address": ":".join(re.findall("..", "%012x" % uuid.getnode())),
"distro_name": distro_name,
"distro_version": distro_version,
"distro_codename": distro_codename,
"cpu_number": psutil.cpu_count(),
"disk_usage": disk_usage,
"ram": "{} GB".format(round(psutil.virtual_memory().total / (1024.0 ** 3))),
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
with open(os.path.join(__location__, "out.json"), "w") as inputfile:
json.dump(config_content, inputfile, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment