diff --git a/stui.py b/stui.py index 12b7d662a7fde9acb7fcc4282914a11e3bcf0539..f1689392a8a4a4016803f7c58fb5e08315b7e10e 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)