我有这个脚本:
#!/bin/bash
myIp=$(ip add sh | grep inet | grep -v -E 'docker|inet6|127'| awk '{print $2}' | cut -d'/' -f1)
mySubnet=$(echo $myIp | cut -d'.' -f 1,2,3)
subnetBits=$(ip add sh | grep inet | grep -v -E 'docker|inet6|127' | awk '{print $2}' | cut -d'/' -f2)
#Check if not 24 bit
if [ $subnetBits -neq 24 ]; then
echo "Subnet other than 24 bit detected - quitting now"
exit 3
fi
for number in {1..254}; do
if curl -s $mySubnet.$number:80 > /dev/null ; then
echo "Found somebody listening on port 80 -- $mySubnet.$number"
fi
done
每次我尝试运行它时,都会出现错误:
script.sh: line 8: [: too many arguments