答案1
这就是我想你想要的。
我替换[ "$1" == ]
为[ -z "$1" ]
,没有更多错误。
#!/bin/bash
if [ -z "$1" ]
then echo "You forgot an ip address!"
echo "Syntax ./ipsweep.sh 192.168.1"
else
for ip in $(seq 1 254)
do ping -c1 $1.$ip |grep "64 bytes"|cut -d " " -f4 |tr -d ":" |tee -a iplist.txt
done
fi
echo -e "\nComplete. Results can be found in the file iplist.txt"
我更换了第二条 ping 线并将其替换为球座命令。它将打印在屏幕上并打印到iplist.txt
文件中。更不用说让你的脚本运行得更快了。