From c4ec39ee673556df2b2f6ed868c7839f91fef796 Mon Sep 17 00:00:00 2001 From: 622ff545dfef6c4fdb84ccec <622ff545dfef6c4fdb84ccec@devide> Date: Mon, 8 May 2023 09:30:01 +0000 Subject: [PATCH] Auto commit --- stui.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/stui.py b/stui.py index 12b7d66..f168939 100644 --- a/stui.py +++ b/stui.py @@ -10,13 +10,31 @@ user_input = st.text_input('输入域名http://') # 判断用户是否有输入,并输出一句问候语 if user_input != '': st.write('正在解析:,', user_input, '......') - # 检测dig是否安装 + + + # 判断当前操作系统是centos还是ubuntu + os_check = subprocess.check_output('cat /etc/*-release | grep -i name', shell=True).decode() + if 'centos' in os_check.lower(): + os_name = 'CentOS' + elif 'ubuntu' in os_check.lower(): + os_name = 'Ubuntu' + else: + os_name = 'Unknown' + + # 判断是否已安装dig try: - subprocess.check_output(["dig", "-v"]) + subprocess.check_output(['which', 'dig']) + print('dig is already installed') except subprocess.CalledProcessError: - # 如果未安装,则安装dig - subprocess.call(["sudo", "apt-get", "update"]) - subprocess.call(["sudo", "apt-get", "install", "-y", "dnsutils"]) + print('dig is not installed') + # 判断操作系统,执行相应的安装命令 + if os_name == 'CentOS': + subprocess.call(['sudo', 'yum', 'install', '-y', 'bind-utils']) + elif os_name == 'Ubuntu': + subprocess.call(['sudo', 'apt-get', 'install', '-y', 'dnsutils']) + else: + print('Unknown operating system') + # 使用subprocess运行dig命令并获取输出 result = subprocess.run(["dig", "+noall", "+answer", user_input ], capture_output=True) -- GitLab