-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysfetch.py
More file actions
93 lines (71 loc) · 2.22 KB
/
Copy pathsysfetch.py
File metadata and controls
93 lines (71 loc) · 2.22 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
#!/usr/bin/env python3
##############################
# sysfetch #
# ======== #
# System information fetching tool
# Copyright (c)2025 Ivaylo Vasilev. Released under the MIT License; see LICENSE for details.
# Author: Ivaylo Vasilev
##############################
import platform
import shutil
import getpass
import socket
from urllib import request, error
import argparse
import sys
# Fetch system information using the default Python libraries
parser = argparse.ArgumentParser(prog="sysfetch", description="System information fetching tool", epilog="(c)Ivaylo Vasilev")
parser.add_argument("--version", action="version", version="%(prog)s 0.6", help="show program version")
args = parser.parse_args()
def main():
information = systemfetch()
print(information)
def systemfetch():
sysinfo = platform.uname()
username = getpass.getuser()
system_platform = sys.platform
localip = local_ip()
publicip = public_ip()
terminal_size = shutil.get_terminal_size()
columns = terminal_size[0]
lines = terminal_size[1]
return f"""
System Information
==================
System : {sysinfo[0]}
Release : {sysinfo[2]}
Version : {sysinfo[3]}
Machine : {sysinfo[4]}
Platform : {system_platform}
Local IP : {localip}
Public IPv4 : {publicip[0]}
Public IPv6 : {publicip[1]}
Username : {username}
Hostname : {sysinfo[1]}
Terminal size : {columns} x {lines}
"""
def local_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(("8.8.8.8", 53))
except OSError:
return "Network is unreachable"
except TimeoutError:
return "Connection time out"
except InterruptedError:
return "Interrupted"
ip = s.getsockname()
return ip[0]
def public_ip():
try:
u4 = request.urlopen("https://ipv4.icanhazip.com")
publicipv4 = u4.read()
u6 = request.urlopen("https://ipv6.icanhazip.com")
publicipv6 = u6.read()
u4.close()
u6.close()
return (publicipv4.decode().strip(), publicipv6.decode().strip())
except error.URLError:
return ("None", "None")
if __name__ == "__main__":
main()