forked from arm0red/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysinfo.py
More file actions
109 lines (93 loc) · 3.25 KB
/
sysinfo.py
File metadata and controls
109 lines (93 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import subprocess
import platform
import os
import json
def get_private_ip():
try:
result = subprocess.check_output(["ip", "addr", "show"]).decode("utf-8")
for line in result.splitlines():
if "inet " in line and "127.0.0.1" not in line:
ip = line.split("inet ")[1].split("/")[0]
return ip
return "Not Found"
except subprocess.CalledProcessError:
return "Not Found"
def get_public_ip():
try:
result = subprocess.check_output(["curl", "-s", "ifconfig.me"]).decode("utf-8").strip()
return result
except subprocess.CalledProcessError:
return "Not Found"
def get_default_gateway():
try:
result = subprocess.check_output(["route", "-n"]).decode("utf-8")
for line in result.splitlines():
if "UG" in line:
return line.split()[2]
return "Not Found"
except subprocess.CalledProcessError:
return "Not Found"
def get_hostname():
return platform.node()
def get_logged_in_users():
try:
result = subprocess.check_output(["who"]).decode("utf-8")
if result.strip():
return result.strip()
else:
return "No users logged in."
except subprocess.CalledProcessError:
return "Not Found"
def get_uptime():
try:
result = subprocess.check_output(["uptime"]).decode("utf-8")
return result.split("up ")[1].strip()
except subprocess.CalledProcessError:
return "Not Found"
def get_storage_info():
try:
result = subprocess.check_output(["df", "-h"]).decode("utf-8")
return result
except subprocess.CalledProcessError:
return "Not Found"
def get_ram_info():
try:
result = subprocess.check_output(["free", "-h"]).decode("utf-8")
return result
except subprocess.CalledProcessError:
return "Not Found"
def get_top_processes():
try:
# Try a much simpler ps command first
result = subprocess.check_output(["ps", "aux"], stderr=subprocess.DEVNULL).decode("utf-8")
return "Could not retrieve detailed process information." # Indicate limitation
except subprocess.CalledProcessError:
return "No processes found."
def main():
system_info = {
"Public IP Address": get_public_ip(),
"Private IP Address": get_private_ip(),
"Default Gateway": get_default_gateway(),
"Hostname": get_hostname(),
"Logged-in Users": get_logged_in_users(),
"Uptime": get_uptime(),
"Storage Information": get_storage_info(),
"RAM Information": get_ram_info(),
"Top Memory Processes": get_top_processes(),
}
print("\033[1;34m" + "System Information" + "\033[0m")
print("-" * 20)
for key, value in system_info.items():
print(f"\033[1;32m{key}\033[0m: \033[1;33m{value}\033[0m")
print("-" * 20)
if __name__ == "__main__":
ascii_art = r"""
_____ _
| _ | | |
__ _ _ __ _ __ ___ | |/' | _ __ ___ __| |
/ _` | '__| '_ ` _ \| /| || '__/ _ \/ _` |
| (_| | | | | | | | \ |_/ /| | | __/ (_| |
\__,_|_| |_| |_| |_|\___(_)_| \___|\__,_|
"""
print(ascii_art)
main()