Linux-批量ping 批量端口探真

批量测试 ip/domain 连通性

#!/bin/bash
    echo ---------------------------Start ping----------------------------
for i in `/usr/bin/cat ~/agent/ping_list/domain`
do
    code=`ping -c 4 -W 3 $i|grep loss|awk '{print $6}'|awk -F "%" '{print $1}'`
if [ $code -eq 100 ];then
    echo -e "\033[31m ping  $i \t Fail  \t\t packet loss: %$code \033[0m"
else
    echo -e "\033[32m ping  $i \t Success \t packet loss: %$code \033[0m"
fi
done
    echo ------------------------------Done-------------------------------

  

批量测试端口连通性

文本:

192.168.1.1 53
192.168.1.1 80
192.168.1.1 87
192.168.1.1 848
192.168.1.2 848

有色脚本:

#!/bin/bash
cat ipport   |  while read line
do
  
#nc -z  -w 10  $line
 
nc -z -w 10 $line > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo -e "\033[32m $line:ok \033[0m"
else
echo -e "\033[31m $line:fail \033[0m"
fi
  
done

  

脚本:

#!/bin/bash
cat testport   |  while read line
do
 
#nc -z  -w 10  $line

nc -z -w 10 $line > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo $line:ok
else
echo $line:fail
fi
 
done
posted @ 2022-01-12 14:27  Security  阅读(834)  评论(0编辑  收藏  举报