#!/bin/bash
if [ -s ./ip_use.txt -o -s ./ip_free.txt ];then
	echo >ip_use.txt
	echo >ip_free.txt
fi

Ip=`ip address show ens18 |awk -F'[ /]+' '/inet /{print $3}'`
Host_Bit=${Ip%.*}
echo "并发ping...."
for (( i=${1:-1};i<=${2:-253};i++ ))
do
  {  ping -c2 -w2 ${Host_Bit}.$i &>/dev/null
    if [ $? -eq 0 ];then
        echo "${Host_Bit}.$i 地址已使用" >>./ip_use.txt
    else
        echo "${Host_Bit}.$i 地址未使用" >>./ip_free.txt
    fi }&
done
wait
echo "并发完成"
