Skip to content

Commit 7d5109f

Browse files
committed
Added Computer Details Script
1 parent c0b68a7 commit 7d5109f

File tree

4 files changed

+276
-0
lines changed

4 files changed

+276
-0
lines changed

Computer-Details/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Computer Details
2+
3+
## 📝 Description
4+
* This Python script tells all the useful details of a computer (Windows) like
5+
* CPU information (Processor, No. of Cores etc.)
6+
* GPU details (GPU name and Version)
7+
* Battery status (Charge Percentage etc)
8+
* Network information (Wifi Address)
9+
* System temperature
10+
* List of installed softwares
11+
* List of connected USB devices
12+
* List of connected audio devices
13+
* Internet connectivity
14+
* Available and used RAM and disk space
15+
<br>
16+
* The script uses <a href="https://pypi.org/project/psutil/">Psutil</a>, <a href="https://docs.python.org/3/library/socket.html">socket</a> and <a href="https://docs.python.org/3/library/platform.html">Platform</a> libraries for this purpose
17+
18+
<br>
19+
20+
## ⚙️ How To Use
21+
22+
Navigate to the project directory and run the following commands :
23+
```bash
24+
pip install -r requirements.txt
25+
```
26+
```bash
27+
python computer-details.py
28+
```
29+
30+
## Output Screenshot
31+
32+
<img src="output.png">
33+
34+
## Author
35+
36+
37+
* <a href="https://github.com/singhchanmeet"> Chanmeet Singh </a>
38+

Computer-Details/computer-details.py

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import psutil
2+
import platform
3+
import subprocess
4+
import socket
5+
6+
# Function to get CPU information
7+
def get_cpu_info():
8+
cpu_info = {}
9+
cpu_info['CPU'] = platform.processor()
10+
cpu_info['Cores'] = psutil.cpu_count(logical=False)
11+
cpu_info['Threads'] = psutil.cpu_count(logical=True)
12+
cpu_info['Clock Speed'] = f"{psutil.cpu_freq().current:.2f} MHz"
13+
return cpu_info
14+
15+
# Function to get GPU information (for any brand)
16+
def get_gpu_info():
17+
gpu_info = {}
18+
try:
19+
gpus = psutil.virtual_memory().available
20+
if gpus:
21+
gpu_info['GPU Name'] = 'Integrated GPU' # If integrated graphics is available
22+
gpu_info['GPU Memory'] = f"{gpus / (1024 ** 3):.2f} GB"
23+
gpu_info['Driver Version'] = 'N/A' # For integrated GPUs, driver version may not be available
24+
else:
25+
result = subprocess.check_output(["nvidia-smi", "--query-gpu=name,memory.total,driver_version", "--format=csv,noheader"], encoding="utf-8")
26+
gpu_name, memory, driver_version = result.strip().split(',')
27+
gpu_info['GPU Name'] = gpu_name
28+
gpu_info['GPU Memory'] = f"{int(memory.strip().split()[0]) / 1024:.2f} GB"
29+
gpu_info['Driver Version'] = driver_version.strip()
30+
except (subprocess.CalledProcessError, FileNotFoundError):
31+
gpu_info['GPU Name'] = 'N/A'
32+
gpu_info['GPU Memory'] = 'N/A'
33+
gpu_info['Driver Version'] = 'N/A'
34+
return gpu_info
35+
36+
# Function to get battery status (for laptops)
37+
def get_battery_status():
38+
battery_status = {}
39+
try:
40+
battery = psutil.sensors_battery()
41+
battery_status['Charge Percentage'] = f"{battery.percent}%"
42+
battery_status['Power Plugged'] = "Yes" if battery.power_plugged else "No"
43+
battery_status['Remaining Time'] = "Unknown" if battery.power_plugged else str(battery.secsleft // 60) + " minutes"
44+
except AttributeError:
45+
battery_status['Charge Percentage'] = 'N/A'
46+
battery_status['Power Plugged'] = 'N/A'
47+
battery_status['Remaining Time'] = 'N/A'
48+
return battery_status
49+
50+
# Function to get network interface information
51+
def get_network_info():
52+
network_info = {}
53+
try:
54+
interfaces = psutil.net_if_addrs()
55+
for interface_name, addresses in interfaces.items():
56+
network_info[interface_name] = []
57+
for address in addresses:
58+
if address.family == socket.AddressFamily.AF_INET:
59+
network_info[interface_name].append(address.address)
60+
except Exception as e:
61+
print(f"Error fetching network information: {e}")
62+
network_info = {}
63+
return network_info
64+
65+
# Function to get system temperature (Linux and Windows only)
66+
def get_system_temperature():
67+
temp_info = {}
68+
try:
69+
# sensors = psutil.sensors_temperatures()
70+
temp_info = psutil.sensors_temperatures()['coretemp'][0].current
71+
# for sensor, entries in sensors.items():
72+
# temp_info[sensor] = [f"{entry.current}°C" for entry in entries]
73+
except Exception as e:
74+
print(f"Error fetching system temperature: {e}")
75+
temp_info = {'Temperature': 'N/A'}
76+
return temp_info
77+
78+
# Function to list installed software (Windows only)
79+
def get_installed_software():
80+
software_list = {}
81+
try:
82+
process = subprocess.Popen(["wmic", "product", "get", "Name"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
83+
stdout, stderr = process.communicate()
84+
software_list['Installed Software'] = [line.strip() for line in stdout.split('\n') if line.strip()]
85+
except FileNotFoundError:
86+
software_list['Installed Software'] = 'N/A'
87+
except Exception as e:
88+
print(f"Error fetching installed software: {e}")
89+
software_list = {'Installed Software': 'N/A'}
90+
return software_list
91+
92+
# Function to list connected USB devices
93+
def get_usb_devices():
94+
usb_devices = []
95+
try:
96+
devices = psutil.disk_partitions(all=True)
97+
for device in devices:
98+
if "removable" in device.opts:
99+
usb_devices.append(device.device)
100+
except Exception as e:
101+
print(f"Error fetching USB devices: {e}")
102+
return usb_devices
103+
104+
# Function to get display information (Windows only)
105+
def get_display_info():
106+
display_info = {}
107+
try:
108+
process = subprocess.Popen(["wmic", "desktopmonitor", "get", "ScreenHeight,ScreenWidth", "/format:list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
109+
stdout, stderr = process.communicate()
110+
lines = [line.strip() for line in stdout.split('\n') if line.strip()]
111+
112+
if len(lines) >= 2:
113+
display_info['Screen Resolution'] = f"{lines[0].split('=')[1]}x{lines[1].split('=')[1]} pixels"
114+
else:
115+
display_info['Screen Resolution'] = 'N/A'
116+
117+
if len(lines) >= 3:
118+
display_info['Color Depth'] = f"{lines[2].split('=')[1]} bits"
119+
else:
120+
display_info['Color Depth'] = 'N/A'
121+
122+
if len(lines) >= 4:
123+
display_info['Refresh Rate'] = f"{lines[3].split('=')[1]} Hz"
124+
else:
125+
display_info['Refresh Rate'] = 'N/A'
126+
127+
except FileNotFoundError:
128+
display_info['Screen Resolution'] = 'N/A'
129+
display_info['Color Depth'] = 'N/A'
130+
display_info['Refresh Rate'] = 'N/A'
131+
except Exception as e:
132+
print(f"Error fetching display information: {e}")
133+
return display_info
134+
135+
# Function to get audio devices information (Windows only)
136+
def get_audio_devices_info():
137+
audio_devices_info = {}
138+
try:
139+
process = subprocess.Popen(["powershell", "(Get-WmiObject -Class Win32_SoundDevice).Name"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
140+
stdout, stderr = process.communicate()
141+
audio_devices_info['Audio Devices'] = [line.strip() for line in stdout.split('\n') if line.strip()]
142+
except FileNotFoundError:
143+
audio_devices_info['Audio Devices'] = 'N/A'
144+
except Exception as e:
145+
print(f"Error fetching audio devices information: {e}")
146+
audio_devices_info = {'Audio Devices': 'N/A'}
147+
return audio_devices_info
148+
149+
# Function to check internet connectivity
150+
def check_internet_connectivity():
151+
try:
152+
subprocess.check_call(["ping", "-c", "1", "www.google.com"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
153+
return True
154+
except subprocess.CalledProcessError:
155+
return False
156+
except Exception as e:
157+
print(f"Error checking internet connectivity: {e}")
158+
return False
159+
160+
# Function to get current date and time
161+
def get_current_date_time():
162+
import datetime
163+
try:
164+
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
165+
except Exception as e:
166+
print(f"Error getting current date and time: {e}")
167+
return 'N/A'
168+
169+
# Function to get total and available RAM and disk space
170+
def get_memory_disk_space_info():
171+
try:
172+
svmem = psutil.virtual_memory()
173+
total_memory_gb = svmem.total / (1024 ** 3)
174+
available_memory_gb = svmem.available / (1024 ** 3)
175+
176+
total_disk = psutil.disk_usage('/')
177+
total_disk_gb = total_disk.total / (1024 ** 3)
178+
available_disk_gb = total_disk.free / (1024 ** 3)
179+
180+
return {
181+
'Total Memory (RAM)': total_memory_gb,
182+
'Available Memory (RAM)': available_memory_gb,
183+
'Total Disk Space': total_disk_gb,
184+
'Available Disk Space': available_disk_gb
185+
}
186+
except Exception as e:
187+
print(f"Error fetching memory and disk space information: {e}")
188+
return {
189+
'Total Memory (RAM)': 'N/A',
190+
'Available Memory (RAM)': 'N/A',
191+
'Total Disk Space': 'N/A',
192+
'Available Disk Space': 'N/A'
193+
}
194+
195+
if __name__ == "__main__":
196+
if platform.system() != 'Windows':
197+
print("Sorry, the script is currently available only for Windows Operating System")
198+
else:
199+
print("\n---- CPU Information ----")
200+
print(get_cpu_info())
201+
202+
print("\n---- GPU Information ----")
203+
print(get_gpu_info())
204+
205+
print("\n---- Battery Status ----")
206+
print(get_battery_status())
207+
208+
print("\n---- Network Interface Information ----")
209+
print(get_network_info())
210+
211+
print("\n---- System Temperature ----")
212+
print(get_system_temperature())
213+
214+
print("\n---- Installed Software ----")
215+
print(get_installed_software())
216+
217+
print("\n---- Connected USB Devices ----")
218+
print(get_usb_devices())
219+
220+
print("\n---- Display Information ----")
221+
print(get_display_info())
222+
223+
print("\n---- Audio Devices Information ----")
224+
print(get_audio_devices_info())
225+
226+
print("\n---- Internet Connectivity ----")
227+
print("Connected" if check_internet_connectivity() else "Disconnected")
228+
229+
print("\n---- Current Date and Time ----")
230+
print(get_current_date_time())
231+
232+
print("\n---- RAM and Disk Space Information ----")
233+
memory_disk_info = get_memory_disk_space_info()
234+
print(f"Total Memory (RAM): {memory_disk_info['Total Memory (RAM)']:.2f} GB")
235+
print(f"Available Memory (RAM): {memory_disk_info['Available Memory (RAM)']:.2f} GB")
236+
print(f"Total Disk Space: {memory_disk_info['Total Disk Space']:.2f} GB")
237+
print(f"Available Disk Space: {memory_disk_info['Available Disk Space']:.2f} GB")

Computer-Details/output.png

91.6 KB
Loading

Computer-Details/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
psutil==5.9.5

0 commit comments

Comments
 (0)