码迷,mamicode.com
首页 > 其他好文 > 详细

主机存活检测、局域网主机存活检测、端口检测

时间:2020-06-25 21:12:07      阅读:38      评论:0      收藏:0      [点我收藏+]

标签:res   lse   down   输入   The   ports   style   端口   nbsp   

一、主机检测命令ping

#!/bin/bash                                                                                                                                                                                 
#****************************************************
#Date:        2020-06-25
#Author:      Damon Ye
#FileName:   MailPing.sh
#Description:The test script
#****************************************************
red="\033[31m"
green="\033[32m"
shutdown="\033[0m"
read -p "请输入你的ip地址:" ipadress
ping -W1 -c3 $ipadress &>/dev/null
if [ $? -eq 0 ];then
  echo -e "$ipadress is ${green}running${shutdown}......"
else
  echo -e "$ipadress is ${red}stopped${shutdown}......"
fi

二、24位掩码局域网主机存活检测

for ip in {1..254}
  do
    ping -w0.1 -W1 -c1 10.0.0.${ip} &>/dev/null
    if [ $? -eq 0 ];then
      echo -e "10.0.0.${ip} is ${green}running${shutdown}......"
    else
      echo -e "10.0.0.${ip} is ${red}stopped${shutdown}......"
    fi
done

三、端口检测

#!/bin/bash
#****************************************************
#Date:        2020-06-25
#Author:      Damon Ye
#FileName:   PortLook.sh
#Description:The test script
#****************************************************
shutdown="\033[0m"
green="\033[32m"
blue="\033[34m"
for ip in {1..254}
 do
   ping -c1 -W1 -w0.1 10.0.0.${ip} &> /dev/null
   if [ $? -eq 0 ];then                                                                                                                                                                     
     echo -e "${green}#################################################${shutdown}"
     echo "Host 10.0.0.${ip} runs on the following ports. "
     nmap 10.0.0.$ip | sed -n /^PORT/,/^MAC/p| sed -n /^[0-9]/p
     echo -e "${blue}#################################################${shutdown}"
     echo -e "\n\n"
   fi
done

 

主机存活检测、局域网主机存活检测、端口检测

标签:res   lse   down   输入   The   ports   style   端口   nbsp   

原文地址:https://www.cnblogs.com/ytdyz/p/13192696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!