批量扫描某个网段中的主机(并发)
创建目录编写脚本文件
mkdir /root/ip_scan_shell/
touch /root/ip_scan_shell/online_server.txt
touch /root/ip_scan_shell/offline_server.txt
touch /root/ip_scan_shell/ip_scan.sh
写入下面shell到脚本文件中
#!/bin/bash
#!/bin/bash
#每次执行脚本时清理上一次运行的主机记录
> /root/ip_scan_shell/online_server.txt
> /root/ip_scan_shell/offline_server.txt
ip="192.168.100."
for host_number in {1..254}
do
( if ping ${ip}${host_number} -c 1 -w 1 &> /dev/null;then
echo "${ip}${host_number} server is online" | tee -a /root/ip_scan_shell/online_server.txt
else
echo "${ip}${host_number} server is offline" | tee -a /root/ip_scan_shell/offline_server.txt
fi ) &
done
wait