#!/bin/bash network=$1 time=$(date +%H%M%S) for i in $(seq $2 $3) do ping -c 1 -w 2 $network.$i > /dev/null if [ $? -eq 0 ]; then arp $network.$i | grep ":" | awk '{print $1,$3}' >> $time.log echo "host $network.$i is up" else echo "host $network.$i is down" fi done
執行命令:bash
./netscan.sh 10.200.201 100 200表示掃描10.200.201.100-10.200.201.200IP是否存活