我当前的脚本:读取IP地址和/检查是否有效范围之间
#!/usr/local/bin/bash
echo -n "Enter VPS IP address:"
read userinput
lookupip="vps $userinput"
if [[ $userinput -lt 80.* || $userinput -gt 255.* ]] #checks input is in the range
then
echo "Input outside acceptable range."
else
#The grep removes all from VPS tool output except primary IP address
$lookupip | grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' | sed '1 ! d' | xargs ping -oc 1000 -Q
fi
最低的IP地址范围在80.XXX范围内,我已经尝试使用:
8 *
80 *
80. 。 *
但它总是有错误:
line 10: [[: 80.X.X.X: syntax error in expression (error token is ".X.X.X")
什么是定义一系列的IP地址小于(LT)和GT(大于)的最好方法?
不要隐藏您在变量中运行的命令。它使得你的代码不易读,并且不能像你认为的那样频繁工作。只需输入'vps $ userinput | grep ...' – chepner
好的,这是有道理的,但我怎么从一个if循环中整齐地调用它呢? – Zippyduda