linux_unix_script_生成ping指令碼

wangzhensheng發表於2009-02-25

scan_host.sh

[@more@]

cat >scan_host.sh<#!/bin/bash
cat $PWD/host.list|while read host;do echo -n "ping ${host} : ";ping -c 3 ${host} >/dev/null ; if [ "$?" -eq "0" ]; then echo "${host} allow ..." ; else echo "${host} deny !!!" ;fi;echo"";echo "" ;done
EOF

注意:生成指令碼的shell中 $符號前用'反斜線'遮蔽'$'符號

直接指令碼

#!/bin/bash
cat $PWD/host.list|while read host port
do echo -n "ping ${host} : "
ping -c 3 ${host} >/dev/null
if [ "$?" -eq "0" ]; then
echo "${host} allow ping ..." ;
else
echo "${host} deny ping !!!" ;
fi;
nmap $host -p $port | grep open>/dev/null
if [ "$?" -eq "0" ]; then
echo "${host} $port allow telnet ..." ;
else
echo "${host} $port deny telnet !!!" ;
fi;
echo"";
echo "" ;
done

chmod 755 scan_host.sh

cat >host.list<xxx.xxx.xxx.xxx port
EOF

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8806316/viewspace-1017835/,如需轉載,請註明出處,否則將追究法律責任。

相關文章