fix: 修改ip校验规则

This commit is contained in:
Olia Lisa
2026-07-22 20:33:39 +08:00
parent aedf70f75b
commit 0e93c1be0c
4 changed files with 29 additions and 9 deletions
+8 -2
View File
@@ -269,13 +269,18 @@ input_lan_ip() {
valid_ipv4() {
local ip="$1"
# 第一层:检查格式,必须是4段数字
echo "$ip" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || return 1
# 第二层:检查每段范围
echo "$ip" | awk -F. '
NF==4 &&
$1>=0 && $1<=255 &&
$2>=0 && $2<=255 &&
$3>=0 && $3<=255 &&
$4>=0 && $4<=255
'
' | grep -q . || return 1
return 0
}
# 项目根目录,用来保证从任意位置执行 main.sh 都能找到其他脚本
@@ -293,6 +298,7 @@ rootfs_partsize=$(ask_input "请输入根分区大小(MB)" "$default_rootfs_part
# lan口ip
default_lan_ip="192.168.1.1"
lan_ip=$(input_lan_ip "$default_lan_ip")
echo $lan_ip
# 安装依赖
install_dependencies