#!/bin/bash # 版权信息 # 四喜科技 免费提供 # 官方网址:https://xi.plus # 多语言支持配置 # 默认语言 default_language="zh_CN" # 语言选择菜单 select_language() { while true; do clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 选择语言 / Select Language ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}1. 中文 (Chinese)${NC}" echo -e "${YELLOW}2. English${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}请选择语言 / Please select language [1-2]: ${NC}" read lang_choice case $lang_choice in 1) return 0 ;; 2) return 1 ;; *) clear echo -e "${RED}无效的选择,请重新输入!${NC}" echo -e "${RED}Invalid choice, please try again!${NC}" echo -n -e "${PURPLE}按任意键继续...${NC}" read -n 1 ;; esac done } # 定义语言数组 # 中文 declare -A LANG_ZH_CN=( [title]="Ubuntu 命令行工具" [copyright]="四喜科技 免费提供" [website]="官方网址:https://xi.plus" [menu_1]="1. 查看系统信息" [menu_2]="2. 查看网络信息" [menu_3]="3. 卸载系统防火墙" [menu_4]="4. 修改网络最大连接数到最大" [menu_5]="5. 系统配置" [menu_6]="6. 系统更新" [menu_7]="7. 安装rinetd" [menu_8]="8. 重启rinetd" [menu_9]="9. 停止rinetd" [menu_10]="10. 配置rinetd" [menu_11]="11. 网络工具" [menu_12]="12. 脚本自动更新" [menu_0]="0. 退出" [prompt_choice]="请输入您的选择 [0-12]:" [system_info_title]="系统信息" [network_info_title]="网络信息" [firewall_uninstall_title]="卸载系统防火墙" [max_connections_title]="修改网络最大连接数" [system_update_title]="系统更新" [rinetd_install_title]="安装rinetd" [rinetd_restart_title]="重启rinetd" [rinetd_stop_title]="停止rinetd" [rinetd_config_title]="配置rinetd" [network_tools_title]="网络工具" [script_update_title]="脚本自动更新" [system_config_title]="系统配置" [back_menu]="按任意键返回菜单..." [thank_you]="感谢使用,再见!" [invalid_choice]="无效的选择,请重新输入!" [please_continue]="按任意键继续..." ) # 英文 declare -A LANG_EN=( [title]="Ubuntu Command Line Tool" [copyright]="Provided by Sixi Technology" [website]="Official Website: https://xi.plus" [menu_1]="1. View System Info" [menu_2]="2. View Network Info" [menu_3]="3. Uninstall Firewall" [menu_4]="4. Set Max Network Connections" [menu_5]="5. System Configuration" [menu_6]="6. System Update" [menu_7]="7. Install rinetd" [menu_8]="8. Restart rinetd" [menu_9]="9. Stop rinetd" [menu_10]="10. Configure rinetd" [menu_11]="11. Network Tools" [menu_12]="12. Update Script" [menu_0]="0. Exit" [prompt_choice]="Please enter your choice [0-12]:" [system_info_title]="System Information" [network_info_title]="Network Information" [firewall_uninstall_title]="Uninstall Firewall" [max_connections_title]="Set Max Network Connections" [system_update_title]="System Update" [rinetd_install_title]="Install rinetd" [rinetd_restart_title]="Restart rinetd" [rinetd_stop_title]="Stop rinetd" [rinetd_config_title]="Configure rinetd" [network_tools_title]="Network Tools" [script_update_title]="Update Script" [system_config_title]="System Configuration" [back_menu]="Press any key to return to menu..." [thank_you]="Thank you for using, goodbye!" [invalid_choice]="Invalid choice, please try again!" [please_continue]="Press any key to continue..." ) # 语言选择 select_language if [ $? -eq 0 ]; then current_language="zh_CN" current_lang_array="LANG_ZH_CN" else current_language="en" current_lang_array="LANG_EN" fi # 获取翻译函数 __() { local key="$1" # 根据当前语言选择对应的数组 if [ "$current_language" == "zh_CN" ]; then echo "${LANG_ZH_CN[$key]}" else echo "${LANG_EN[$key]}" fi } # 定义颜色变量 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' NC='\033[0m' # No Color # 错误处理函数 error_handler() { local exit_code=$1 local line_num=$2 local command=$3 local error_msg="脚本在第 $line_num 行执行 '$command' 时失败,退出码: $exit_code" log_message "ERROR" "$error_msg" echo -e "${RED}[ERROR] $error_msg${NC}" echo -e "${YELLOW}请检查命令执行情况,或联系技术支持。${NC}" read -n 1 -p "按任意键返回菜单..." # 恢复正常执行流程 set +e } # 设置全局错误捕获 trap 'error_handler $? $LINENO "$BASH_COMMAND"' ERR # 设置严格模式 set -euo pipefail # 性能优化:跟踪apt-get update是否已执行 APT_UPDATED=false # 日志配置 LOG_DIR="/var/log/linux-tool" LOG_FILE="$LOG_DIR/linux-tool.log" # 创建日志目录 mkdir -p "$LOG_DIR" 2>/dev/null # 日志记录函数 log_message() { local level=$1 local message=$2 local timestamp=$(date "+%Y-%m-%d %H:%M:%S") echo "[$timestamp] [$level] $message" >> "$LOG_FILE" # 仅将错误级别输出到控制台 if [ "$level" == "ERROR" ]; then echo -e "${RED}[$timestamp] [$level] $message${NC}" fi } # 性能优化:智能apt-get update函数 # 只在需要时执行apt-get update,避免重复调用 smart_apt_update() { if [ "$APT_UPDATED" == "false" ]; then echo -e "${YELLOW}正在更新包列表...${NC}" sudo apt-get update APT_UPDATED=true log_message "INFO" "执行apt-get update" fi } # 清除屏幕 clear # 记录脚本启动日志 log_message "INFO" "脚本启动,当前用户: $(whoami),当前目录: $(pwd)" # 脚本自动更新功能 update_script() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 脚本自动更新 ${NC}" echo -e "${CYAN}==========================================${NC}" log_message "INFO" "开始执行脚本自动更新" local script_path="$(realpath "$0")" local script_dir="$(dirname "$script_path")" echo -e "${YELLOW}正在检查更新...${NC}" # 进入脚本目录 cd "$script_dir" || { echo -e "${RED}无法进入脚本目录!${NC}" log_message "ERROR" "无法进入脚本目录: $script_dir" read -n 1 -p "按任意键返回菜单..." return 1 } # 检查是否为git仓库 if [ ! -d ".git" ]; then echo -e "${RED}当前目录不是git仓库,无法自动更新!${NC}" log_message "ERROR" "当前目录不是git仓库,无法自动更新" read -n 1 -p "按任意键返回菜单..." return 1 fi # 拉取最新代码 git pull origin main 2>&1 | tee -a "$LOG_FILE" || { echo -e "${RED}拉取更新失败!${NC}" log_message "ERROR" "git pull 失败" read -n 1 -p "按任意键返回菜单..." return 1 } echo -e "${GREEN}脚本更新完成!${NC}" echo -e "${YELLOW}请重新运行脚本以使用最新版本。${NC}" log_message "INFO" "脚本更新完成" read -n 1 -p "按任意键返回菜单..." } # 网络工具功能菜单 network_tools() { while true; do clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 网络工具 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}1. 网络测速 (speedtest-cli)${NC}" echo -e "${YELLOW}2. 端口扫描 (nmap)${NC}" echo -e "${YELLOW}3. 查看网络连接${NC}" echo -e "${YELLOW}4. DNS测试 (dig)${NC}" echo -e "${YELLOW}5. 路由追踪 (traceroute)${NC}" echo -e "${YELLOW}6. Ping测试${NC}" echo -e "${YELLOW}7. 域名解析测试${NC}" echo -e "${YELLOW}8. 网络流量监控${NC}" echo -e "${YELLOW}9. 查看MAC地址${NC}" echo -e "${YELLOW}10. 查看ARP表${NC}" echo -e "${YELLOW}0. 返回主菜单${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}请输入您的选择 [0-10]: ${NC}" read net_choice case $net_choice in 1) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 网络测速 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检查speedtest-cli是否安装 if ! command -v speedtest-cli &> /dev/null; then echo -e "${YELLOW}正在安装speedtest-cli...${NC}" smart_apt_update sudo apt-get install -y speedtest-cli fi echo -e "${YELLOW}开始网络测速...${NC}" speedtest-cli log_message "INFO" "执行网络测速" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 2) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 端口扫描 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检查nmap是否安装 if ! command -v nmap &> /dev/null; then echo -e "${YELLOW}正在安装nmap...${NC}" smart_apt_update sudo apt-get install -y nmap fi echo -n -e "${PURPLE}请输入要扫描的目标IP或域名: ${NC}" read target echo -e "${YELLOW}开始扫描目标 ${target}...${NC}" sudo nmap -sS -p 1-1000 $target log_message "INFO" "执行端口扫描,目标: $target" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 3) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看网络连接 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}1. 使用 netstat 查看${NC}" echo -e "${YELLOW}2. 使用 ss 查看${NC}" echo -n -e "${PURPLE}请选择工具 [1-2]: ${NC}" read conn_tool case $conn_tool in 1) # 检查netstat是否安装 if ! command -v netstat &> /dev/null; then echo -e "${YELLOW}正在安装net-tools...${NC}" smart_apt_update sudo apt-get install -y net-tools fi echo -e "${YELLOW}使用 netstat 查看网络连接:${NC}" sudo netstat -tuln ;; 2) # 检查ss是否安装 if ! command -v ss &> /dev/null; then echo -e "${YELLOW}正在安装iproute2...${NC}" smart_apt_update sudo apt-get install -y iproute2 fi echo -e "${YELLOW}使用 ss 查看网络连接:${NC}" sudo ss -tuln ;; *) echo -e "${RED}无效的选择!${NC}" ;; esac log_message "INFO" "查看网络连接,使用工具: $conn_tool" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 4) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} DNS测试 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检查dig是否安装 if ! command -v dig &> /dev/null; then echo -e "${YELLOW}正在安装dnsutils...${NC}" smart_apt_update sudo apt-get install -y dnsutils fi echo -n -e "${PURPLE}请输入要测试的域名: ${NC}" read domain echo -e "${YELLOW}开始DNS测试...${NC}" dig $domain log_message "INFO" "执行DNS测试,域名: $domain" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 5) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 路由追踪 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检查traceroute是否安装 if ! command -v traceroute &> /dev/null; then echo -e "${YELLOW}正在安装traceroute...${NC}" smart_apt_update sudo apt-get install -y traceroute fi echo -n -e "${PURPLE}请输入要追踪的目标IP或域名: ${NC}" read target echo -e "${YELLOW}开始路由追踪...${NC}" traceroute $target log_message "INFO" "执行路由追踪,目标: $target" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 6) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} Ping测试 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}请输入要ping的目标IP或域名: ${NC}" read target echo -n -e "${PURPLE}请输入ping的次数(默认4次): ${NC}" read count count=${count:-4} echo -e "${YELLOW}开始Ping测试...${NC}" ping -c $count $target log_message "INFO" "执行Ping测试,目标: $target,次数: $count" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 7) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 域名解析测试 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检查nslookup是否安装 if ! command -v nslookup &> /dev/null; then echo -e "${YELLOW}正在安装dnsutils...${NC}" smart_apt_update sudo apt-get install -y dnsutils fi echo -n -e "${PURPLE}请输入要解析的域名: ${NC}" read domain echo -e "${YELLOW}开始域名解析测试...${NC}" nslookup $domain log_message "INFO" "执行域名解析测试,域名: $domain" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 8) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 网络流量监控 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检查ifstat是否安装 if ! command -v ifstat &> /dev/null; then echo -e "${YELLOW}正在安装ifstat...${NC}" smart_apt_update sudo apt-get install -y ifstat fi echo -e "${YELLOW}开始网络流量监控...${NC}" echo -e "${YELLOW}按 Ctrl+C 停止监控${NC}" ifstat -t log_message "INFO" "执行网络流量监控" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 9) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看MAC地址 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}网络接口MAC地址:${NC}" ip link show | grep -E 'ether|link/ether' log_message "INFO" "查看MAC地址" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 10) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看ARP表 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}ARP表内容:${NC}" arp -a log_message "INFO" "查看ARP表" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回网络工具菜单...${NC}" read -n 1 ;; 0) break ;; *) clear echo -e "${RED}无效的选择,请重新输入!${NC}" echo -n -e "${PURPLE}按任意键继续...${NC}" read -n 1 ;; esac done } # 系统配置子菜单 system_config() { while true; do clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 系统配置 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}1. 查看CPU使用率${NC}" echo -e "${YELLOW}2. 查看内存使用率${NC}" echo -e "${YELLOW}3. 查看磁盘使用率${NC}" echo -e "${YELLOW}4. 查看系统负载${NC}" echo -e "${YELLOW}5. 查看登录用户信息${NC}" echo -e "${YELLOW}6. 查看系统服务状态${NC}" echo -e "${YELLOW}0. 返回主菜单${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}请输入您的选择 [0-6]: ${NC}" read config_choice case $config_choice in 1) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看CPU使用率 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}CPU使用率 (按 Ctrl+C 停止):${NC}" top -bn1 | grep "%Cpu(s)" || mpstat log_message "INFO" "查看CPU使用率" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回系统配置菜单...${NC}" read -n 1 ;; 2) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看内存使用率 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}内存使用情况:${NC}" free -h echo -e "\n${YELLOW}详细内存信息:${NC}" cat /proc/meminfo | head -20 log_message "INFO" "查看内存使用率" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回系统配置菜单...${NC}" read -n 1 ;; 3) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看磁盘使用率 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}磁盘分区使用率:${NC}" df -h echo -e "\n${YELLOW}磁盘I/O统计:${NC}" iostat -x log_message "INFO" "查看磁盘使用率" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回系统配置菜单...${NC}" read -n 1 ;; 4) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看系统负载 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}系统负载:${NC}" uptime echo -e "\n${YELLOW}详细负载信息:${NC}" top -bn1 | head -20 log_message "INFO" "查看系统负载" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回系统配置菜单...${NC}" read -n 1 ;; 5) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看登录用户信息 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}当前登录用户:${NC}" w echo -e "\n${YELLOW}用户登录历史:${NC}" last | head -20 log_message "INFO" "查看登录用户信息" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回系统配置菜单...${NC}" read -n 1 ;; 6) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 查看系统服务状态 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}1. 查看所有服务状态${NC}" echo -e "${YELLOW}2. 查看特定服务状态${NC}" echo -n -e "${PURPLE}请选择 [1-2]: ${NC}" read service_choice case $service_choice in 1) echo -e "${YELLOW}所有服务状态:${NC}" systemctl list-units --type=service --state=running | head -30 log_message "INFO" "查看所有服务状态" ;; 2) echo -n -e "${PURPLE}请输入服务名称: ${NC}" read service_name echo -e "${YELLOW}服务 ${service_name} 状态:${NC}" systemctl status $service_name log_message "INFO" "查看服务状态,服务名称: $service_name" ;; *) echo -e "${RED}无效的选择!${NC}" ;; esac echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回系统配置菜单...${NC}" read -n 1 ;; 0) break ;; *) clear echo -e "${RED}无效的选择,请重新输入!${NC}" echo -n -e "${PURPLE}按任意键继续...${NC}" read -n 1 ;; esac done } # 主菜单函数 show_menu() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} $(__ title) ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${PURPLE} $(__ copyright) ${NC}" echo -e "${BLUE} $(__ website) ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}$(__ menu_1)${NC}" echo -e "${YELLOW}$(__ menu_2)${NC}" echo -e "${YELLOW}$(__ menu_3)${NC}" echo -e "${YELLOW}$(__ menu_4)${NC}" echo -e "${YELLOW}$(__ menu_5)${NC}" echo -e "${YELLOW}$(__ menu_6)${NC}" echo -e "${YELLOW}$(__ menu_7)${NC}" echo -e "${YELLOW}$(__ menu_8)${NC}" echo -e "${YELLOW}$(__ menu_9)${NC}" echo -e "${YELLOW}$(__ menu_10)${NC}" echo -e "${YELLOW}$(__ menu_11)${NC}" echo -e "${YELLOW}$(__ menu_12)${NC}" echo -e "${YELLOW}$(__ menu_0)${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}$(__ prompt_choice) ${NC}" } # 查看系统信息 view_system_info() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 系统信息 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}操作系统:${NC} $(lsb_release -d | cut -f2)" echo -e "${YELLOW}内核版本:${NC} $(uname -r)" echo -e "${YELLOW}CPU信息:${NC} $(lscpu | grep 'Model name' | cut -f2 -d:)" echo -e "${YELLOW}内存信息:${NC} $(free -h | grep Mem | awk '{print $2}')" echo -e "${YELLOW}磁盘信息:${NC} $(df -h | grep '/dev/' | grep -v tmpfs)" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 查看网络信息 view_network_info() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 网络信息 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}IP地址:${NC} $(ip addr show | grep inet | grep -v 127.0.0.1 | cut -d' ' -f6 | cut -d'/' -f1)" echo -e "${YELLOW}网关:${NC} $(ip route | grep default | cut -d' ' -f3)" echo -e "${YELLOW}DNS服务器:${NC} $(cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2)" echo -e "${YELLOW}网络接口:${NC} $(ip link show | grep UP | grep -v lo | cut -d':' -f2)" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 卸载系统防火墙 uninstall_firewall() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 卸载系统防火墙 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}正在卸载ufw...${NC}" sudo apt-get remove -y ufw sudo apt-get purge -y ufw echo -e "${GREEN}防火墙卸载完成!${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 修改网络最大连接数到最大 modify_max_connections() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 修改网络最大连接数 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}正在修改网络最大连接数...${NC}" # 修改系统限制 echo "* soft nofile 65535" | sudo tee -a /etc/security/limits.conf echo "* hard nofile 65535" | sudo tee -a /etc/security/limits.conf # 修改sysctl配置 echo "net.core.somaxconn = 65535" | sudo tee -a /etc/sysctl.conf echo "net.ipv4.tcp_max_syn_backlog = 65535" | sudo tee -a /etc/sysctl.conf echo "net.ipv4.tcp_max_tw_buckets = 65535" | sudo tee -a /etc/sysctl.conf # 应用sysctl配置 sudo sysctl -p echo -e "${GREEN}网络最大连接数修改完成!${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 支持的Linux发行版和版本 # Ubuntu declare -A SUPPORTED_UBUNTU_VERSIONS=( ["trusty"]="14.04 LTS" ["xenial"]="16.04 LTS" ["bionic"]="18.04 LTS" ["focal"]="20.04 LTS" ["jammy"]="22.04 LTS" ["noble"]="24.04 LTS" ["oracular"]="24.10" ) # Debian declare -A SUPPORTED_DEBIAN_VERSIONS=( ["jessie"]="8 LTS" ["stretch"]="9 LTS" ["buster"]="10 LTS" ["bullseye"]="11 LTS" ["bookworm"]="12 LTS" ["trixie"]="13" ["forky"]="14" ) # 系统更新功能 system_update() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 系统更新 ${NC}" echo -e "${CYAN}==========================================${NC}" # 检测Linux发行版 if command -v lsb_release &> /dev/null; then OS_NAME=$(lsb_release -i | cut -f2) CURRENT_VERSION=$(lsb_release -c | cut -f2) CURRENT_RELEASE=$(lsb_release -r | cut -f2) elif [ -f /etc/os-release ]; then source /etc/os-release OS_NAME=$NAME CURRENT_VERSION=$VERSION_CODENAME CURRENT_RELEASE=$VERSION_ID else echo -e "${RED}无法检测系统版本!${NC}" log_message "ERROR" "无法检测系统版本" read -n 1 -p "按任意键返回菜单..." return 1 fi echo -e "${YELLOW}当前系统: ${OS_NAME} ${CURRENT_RELEASE} (${CURRENT_VERSION})${NC}" # 确定包管理器 if command -v apt-get &> /dev/null; then PM="apt" elif command -v yum &> /dev/null; then PM="yum" elif command -v dnf &> /dev/null; then PM="dnf" else echo -e "${RED}不支持的包管理器!${NC}" log_message "ERROR" "不支持的包管理器" read -n 1 -p "按任意键返回菜单..." return 1 fi echo -e "${YELLOW}包管理器: ${PM}${NC}" # 显示支持的版本 if [[ "$OS_NAME" == *"Ubuntu"* ]]; then echo -e "${YELLOW}支持的Ubuntu版本:${NC}" for version in "${!SUPPORTED_UBUNTU_VERSIONS[@]}"; do echo -e " - ${version}: ${SUPPORTED_UBUNTU_VERSIONS[$version]}" done elif [[ "$OS_NAME" == *"Debian"* ]]; then echo -e "${YELLOW}支持的Debian版本:${NC}" for version in "${!SUPPORTED_DEBIAN_VERSIONS[@]}"; do echo -e " - ${version}: ${SUPPORTED_DEBIAN_VERSIONS[$version]}" done fi echo -e "\n${YELLOW}1. 自动更新${NC}" echo -n -e "${PURPLE}请输入您的选择 [1]: ${NC}" read update_choice case $update_choice in 1) echo -e "${YELLOW}正在执行系统更新...${NC}" log_message "INFO" "开始系统更新,当前版本: ${CURRENT_VERSION}" case $PM in apt) # apt包管理器 (Debian/Ubuntu) sudo apt-get update sudo apt-get upgrade -y sudo apt-get dist-upgrade -y sudo apt-get autoremove -y ;; yum) # yum包管理器 (CentOS 6/7) sudo yum update -y sudo yum upgrade -y ;; dnf) # dnf包管理器 (CentOS 8+, Fedora) sudo dnf update -y sudo dnf upgrade -y ;; *) echo -e "${RED}不支持的包管理器!${NC}" log_message "ERROR" "不支持的包管理器: $PM" read -n 1 -p "按任意键返回菜单..." return 1 ;; esac echo -e "${GREEN}系统更新完成!${NC}" log_message "INFO" "系统更新完成" ;; *) echo -e "${RED}无效的选择!${NC}" log_message "WARNING" "无效的更新选择: ${update_choice}" ;; esac echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 安装rinetd install_rinetd() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 安装rinetd ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}正在安装rinetd...${NC}" smart_apt_update sudo apt-get install -y rinetd echo -e "${GREEN}rinetd安装完成!${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 重启rinetd restart_rinetd() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 重启rinetd ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}正在重启rinetd...${NC}" sudo systemctl restart rinetd echo -e "${GREEN}rinetd重启完成!${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 停止rinetd stop_rinetd() { clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 停止rinetd ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}正在停止rinetd...${NC}" sudo systemctl stop rinetd echo -e "${GREEN}rinetd停止完成!${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回菜单...${NC}" read -n 1 } # 配置rinetd configure_rinetd() { while true; do clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 配置rinetd ${NC}" echo -e "${CYAN}==========================================${NC}" echo -e "${YELLOW}1. 查看当前中转配置${NC}" echo -e "${YELLOW}2. 添加中转配置${NC}" echo -e "${YELLOW}3. 修改中转配置${NC}" echo -e "${YELLOW}4. 删除中转配置${NC}" echo -e "${YELLOW}0. 返回主菜单${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}请输入您的选择 [0-4]: ${NC}" read rinetd_choice case $rinetd_choice in 1) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 当前中转配置 ${NC}" echo -e "${CYAN}==========================================${NC}" if [ -f /etc/rinetd.conf ]; then echo -e "${YELLOW}配置内容:${NC}" cat /etc/rinetd.conf else echo -e "${RED}rinetd配置文件不存在!${NC}" fi echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回rinetd配置菜单...${NC}" read -n 1 ;; 2) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 添加中转配置 ${NC}" echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}输入本地IP(默认0.0.0.0): ${NC}" read local_ip local_ip=${local_ip:-0.0.0.0} echo -n -e "${PURPLE}输入本地端口: ${NC}" read local_port echo -n -e "${PURPLE}输入目标域名: ${NC}" read target_domain echo -n -e "${PURPLE}输入目标端口: ${NC}" read target_port echo -n -e "${PURPLE}是否添加到配置文件?(y/n,默认y): ${NC}" read add_to_file add_to_file=${add_to_file:-y} if [ "$add_to_file" == "y" ] || [ "$add_to_file" == "Y" ]; then echo "$local_ip $local_port $target_domain $target_port" | sudo tee -a /etc/rinetd.conf echo -e "${GREEN}中转配置添加完成!${NC}" # 配置修改后立即重启rinetd echo -e "${YELLOW}正在重启rinetd...${NC}" sudo systemctl restart rinetd echo -e "${GREEN}rinetd重启完成!${NC}" fi echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回rinetd配置菜单...${NC}" read -n 1 ;; 3) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 修改中转配置 ${NC}" echo -e "${CYAN}==========================================${NC}" if [ -f /etc/rinetd.conf ]; then # 显示当前配置并编号 echo -e "${YELLOW}当前配置:${NC}" sudo awk '{print NR ". " $0}' /etc/rinetd.conf echo -n -e "${PURPLE}输入要修改的配置项序号: ${NC}" read config_num # 获取当前配置行 current_config=$(sudo sed -n "${config_num}p" /etc/rinetd.conf) if [ -n "$current_config" ]; then # 解析当前配置 current_local_ip=$(echo $current_config | awk '{print $1}') current_local_port=$(echo $current_config | awk '{print $2}') current_target_domain=$(echo $current_config | awk '{print $3}') current_target_port=$(echo $current_config | awk '{print $4}') echo -n -e "${PURPLE}输入新的本地IP(默认$current_local_ip): ${NC}" read new_local_ip new_local_ip=${new_local_ip:-$current_local_ip} echo -n -e "${PURPLE}输入新的本地端口(默认$current_local_port): ${NC}" read new_local_port new_local_port=${new_local_port:-$current_local_port} echo -n -e "${PURPLE}输入新的目标域名(默认$current_target_domain): ${NC}" read new_target_domain new_target_domain=${new_target_domain:-$current_target_domain} echo -n -e "${PURPLE}输入新的目标端口(默认$current_target_port): ${NC}" read new_target_port new_target_port=${new_target_port:-$current_target_port} echo -n -e "${PURPLE}是否保存修改?(y/n,默认y): ${NC}" read save_changes save_changes=${save_changes:-y} if [ "$save_changes" == "y" ] || [ "$save_changes" == "Y" ]; then # 修改配置文件 sudo sed -i "${config_num}c ${new_local_ip} ${new_local_port} ${new_target_domain} ${new_target_port}" /etc/rinetd.conf echo -e "${GREEN}中转配置修改完成!${NC}" # 配置修改后立即重启rinetd echo -e "${YELLOW}正在重启rinetd...${NC}" sudo systemctl restart rinetd echo -e "${GREEN}rinetd重启完成!${NC}" fi else echo -e "${RED}无效的配置项序号!${NC}" fi else echo -e "${RED}rinetd配置文件不存在!${NC}" fi echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回rinetd配置菜单...${NC}" read -n 1 ;; 4) clear echo -e "${CYAN}==========================================${NC}" echo -e "${GREEN} 删除中转配置 ${NC}" echo -e "${CYAN}==========================================${NC}" if [ -f /etc/rinetd.conf ]; then # 显示当前配置并编号 echo -e "${YELLOW}当前配置:${NC}" sudo awk '{print NR ". " $0}' /etc/rinetd.conf echo -n -e "${PURPLE}输入要删除的配置项序号: ${NC}" read config_num # 检查配置项是否存在 current_config=$(sudo sed -n "${config_num}p" /etc/rinetd.conf) if [ -n "$current_config" ]; then echo -n -e "${PURPLE}是否删除该配置项?(y/n,默认y): ${NC}" read delete_config delete_config=${delete_config:-y} if [ "$delete_config" == "y" ] || [ "$delete_config" == "Y" ]; then # 删除配置行 sudo sed -i "${config_num}d" /etc/rinetd.conf echo -e "${GREEN}中转配置删除完成!${NC}" # 配置修改后立即重启rinetd echo -e "${YELLOW}正在重启rinetd...${NC}" sudo systemctl restart rinetd echo -e "${GREEN}rinetd重启完成!${NC}" fi else echo -e "${RED}无效的配置项序号!${NC}" fi else echo -e "${RED}rinetd配置文件不存在!${NC}" fi echo -e "${CYAN}==========================================${NC}" echo -n -e "${PURPLE}按任意键返回rinetd配置菜单...${NC}" read -n 1 ;; 0) break ;; *) echo -e "${RED}无效的选择!${NC}" echo -n -e "${PURPLE}按任意键继续...${NC}" read -n 1 ;; esac done } # 主循环 while true; do show_menu read choice case $choice in 1) log_message "INFO" "用户选择:查看系统信息" view_system_info ;; 2) log_message "INFO" "用户选择:查看网络信息" view_network_info ;; 3) log_message "INFO" "用户选择:卸载系统防火墙" uninstall_firewall ;; 4) log_message "INFO" "用户选择:修改网络最大连接数" modify_max_connections ;; 5) log_message "INFO" "用户选择:系统配置" system_config ;; 6) log_message "INFO" "用户选择:系统更新" system_update ;; 7) log_message "INFO" "用户选择:安装rinetd" install_rinetd ;; 8) log_message "INFO" "用户选择:重启rinetd" restart_rinetd ;; 9) log_message "INFO" "用户选择:停止rinetd" stop_rinetd ;; 10) log_message "INFO" "用户选择:配置rinetd" configure_rinetd ;; 11) log_message "INFO" "用户选择:网络工具" network_tools ;; 12) log_message "INFO" "用户选择:脚本自动更新" update_script ;; 0) log_message "INFO" "用户选择:退出脚本" clear echo -e "${GREEN}$(__ thank_you)${NC}" exit 0 ;; *) log_message "WARNING" "用户输入无效选择:$choice" clear echo -e "${RED}$(__ invalid_choice)${NC}" echo -n -e "${PURPLE}$(__ please_continue)${NC}" read -n 1 ;; esac done