shell实现局域网IP扫描

简单shell实现局域网IP扫描

简单shell实现局域网IP扫描
局域网主机联通性的扫描

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#简单shell实现局域网IP扫描
#Functions: 局域网主机联通性的扫描
#Author: ljw

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

执行

1
./netscan.sh 172.18.22 100 130

结果

1
2
3
4
5
6
7
8
# sh netscan.sh 172.18.22 100 130
host 172.18.22.100 is up
host 172.18.22.101 is up
host 172.18.22.102 is up
host 172.18.22.103 is up
host 172.18.22.104 is down
host 172.18.22.105 is down
host 172.18.22.106 is down