feat: 扫描子网可达主机脚本
This commit is contained in:
parent
a4d375af41
commit
6a12113be3
25
scripts/network/check-subnet.sh
Normal file
25
scripts/network/check-subnet.sh
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#Program:
|
||||||
|
# 扫描子网可达的主机
|
||||||
|
#History:
|
||||||
|
# 2024/07/14 LouisFonda<yigencong@yahoo.com>
|
||||||
|
subnet="192.168.1"
|
||||||
|
reachable_hosts=()
|
||||||
|
|
||||||
|
# 循环遍历子网中的所有IP地址
|
||||||
|
for (( i=1; i<=255; i++ ))
|
||||||
|
do
|
||||||
|
ip="$subnet.$i"
|
||||||
|
|
||||||
|
# 发送单个ICMP回显请求,等待1秒钟,最多发送1次
|
||||||
|
ping -c 1 -W 1 "$ip" > /dev/null 2>&1
|
||||||
|
|
||||||
|
# 检查ping命令的退出状态
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "$ip 可达"
|
||||||
|
reachable_hosts+=("$ip")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "可达主机列表:"
|
||||||
|
echo "${reachable_hosts[@]}"
|
Loading…
x
Reference in New Issue
Block a user