ping.sh

扫描整个网段  nmap -sP 10.0.0.0/24

#!/bin/bash

ps () {

ping $1 -c 3 -w 2 |grep -q "ttl"      #结果有ttl   $?为真

if [ $? -eq 0 ]
then
echo "ping $1 pass"
else
echo "ping $1 lost"
echo `date`|mail -s "$1 lost" testping159258@126.com
fi
sleep 2
}
while :;do    # 或while true ;do        while [ 1 -eq 1 ]  ;do
ps 192.168.1.200
ps 192.168.1.201
done

 

#!/usr/bin/env python
#coding:utf-8
import os
a=raw_input("a:")
b=raw_input("b:")  #raw_input() 传回的是字符串 所以需要转换   range跟整数
v=('192.168.1.%d' % (x) for x in range(int(a),int(b)))
for it in v:
    ret = os.system('ping -c 1 -w 1  %s |grep -q ttl' % it)
    if ret:
        print 'ping %s fail' % it
    else:
        print 'ping %s ok' % it                                                                                                      

原文地址:https://www.cnblogs.com/hanxing/p/4055001.html