【发布时间】:2015-10-10 16:42:06
【问题描述】:
是否可以以另一种方式编写此脚本来增加 IP 地址,而不会像这样循环?脚本,一个端口扫描器,工作正常,我的只是一个关于效率的问题。对不起我的英语,谢谢你的回答。
#!/bin/bash
ip=$1
IFS=. read i1 i2 i3 i4 <<< "$ip"
port=$2
max=255
while [ $i1 -le $max ];do
while [ $i2 -le $max ]; do
while [ $i3 -le $max ]; do
while [ $i4 -le $max ]; do
timeout 0.4 bash -c "echo >/dev/tcp/$i1.$i2.$i3.$i4/$port" && echo "on $i1.$i2.$i3.$i4 port $port is open"
i4=$(($i4+1))
done
i4=0
i3=$(($i3+1))
done
i3=0
i2=$(($i2+1))
done
i2=0
i1=$(($i1+1))
done
【问题讨论】: