Files
ShellCrash/scripts/menus/check_port.sh
Sofia 180629c8dd perf: optimize port validation with efficient grep usage
- Use 'grep -q' to avoid unnecessary output and sub-shell usage
2026-01-18 09:14:43 +08:00

18 lines
581 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Copyright (C) Juewuy
check_port() {
if [ "$1" -gt 65535 ] || [ "$1" -le 1 ]; then
echo -e "\033[31m输入错误请输入正确的数值(1-65535)\033[0m"
return 1
elif echo "|$mix_port|$redir_port|$dns_port|$db_port|" | grep -q "|$1|"; then
echo -e "\033[31m输入错误请不要输入重复的端口\033[0m"
return 1
elif netstat -ntul | grep -q ":$1[[:space:]]"; then
echo -e "\033[31m当前端口已被其他进程占用请重新输入\033[0m"
return 1
else
return 0
fi
}