import streamlit as st import subprocess # 创建一个标题 st.title('Python 解析域名IP地址') # 创建一个文本框并接收用户输入 user_input = st.text_input('输入域名http://') # 判断用户是否有输入,并输出一句问候语 if user_input != '': st.write('正在解析:,', user_input, '......') # 判断当前操作系统是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(['which', 'dig']) print('dig is already installed') except subprocess.CalledProcessError: 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) # 将输出转换为表格 output_lines = result.stdout.decode('utf-8').strip().split('\n') table = [line.split() for line in output_lines] # 将表格输出到streamlit界面 st.table(table) else: st.write('这是一个dig的UI界面,Stremlit太强到了')