#!/bin/bash
#yum install -y nmap # 安装扫描工具
read -p "请输入域名或IP地址进行检测:" eaddress
read -p "请选择执行方式:1 为端口范围,2 为指定端口,由数组 eport 控制" ecase
startp=60000 # 端口开始扫描范围
endp=60100 # 结束范围
eport=(
80 443 6379 3389 22
)
fanwei (){
for((i=$startp;i<=$endp;i++))
do
statusP=$(nmap -p $i $eaddress -Pn | grep $i | awk -F" " '{print $2}'| sed 's/ //g' ) ; echo "$eaddress $i ----- ${statusP}"
if [[ $statusP = "open" ]]; then
echo "端口---------> $i 通畅"
elif [[ $statusP = "closed" ]]; then
echo "端口: $i 开放,没有服务运行该端口"
else
echo "端口没开放"
fi
done
}
zhiding(){
for i in ${eport[*]}
do
statusP=$(nmap -p $i $eaddress -Pn | grep $i | awk -F" " '{print $2}'| sed 's/ //g' ) ; echo "$eaddress $i ----- ${statusP}"
if [[ $statusP = "open" ]]; then
echo "端口---------> $i 通畅"
elif [[ $statusP = "closed" ]]; then
echo "端口: $i 开放,没有服务运行该端口"
else
echo "端口没开放"
fi
done
}
case $ecase in
"1") echo "您选择了使用端口范围方式扫描"
fanwei
;;
"2")echo "指定端口扫描"
zhiding
;;
*)echo "选择无效,请重新输入!"
exit
;;
esac
# wget eisc.cn/file/shell/nmap.sh ; sh nmap.sh
# 执行脚本