1
可以用另一種方式寫這個腳本來增加這樣的ip地址whitout循環嗎?腳本,一個端口掃描器,工作正常,我的只是一個關於效率的問題。對不起,我的英語和感謝您的答案。在一個shell腳本中增加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
有沒有辦法在文本文件中輸入eval命令的輸出? –
你是不是這個意思? '因爲我在$ ip;做回聲「$我」;完成' – Cyrus
是的,但在這種情況下,我們將利用另一個循環方案,而從而。 eval是有趣的函數謝謝,但我怎麼能操縱輸出元素?因爲你發佈的腳本給了我一個完整的輸出流。謝謝你的時間賽勒斯 –