我正在尝试编写一个bash脚本来确定网络上可用的所有主机的IP地址和MAC地址。出于某种原因,Pingpacklist文件不断变空。我知道arp中的条目并不是永久性的,所以我认为在ping半个网络后转储arp。但它似乎仍然无法获得所有地址的ARP条目。任何建议?网络上的可用主机
#! /bin/bash
tcpdump -i eth1 -n icmp >> Pingpacketlist &
count=0
mod=127;
for ip in 172.16.1.{1..254}; do
let count=count+1;
let res=$count%$mod;
ping -c 1 -W 1 $ip > /dev/null 2> /dev/null;
if [ $? -eq 0 ]; then # for debugging
echo "${ip} is up";
else
echo "${ip} is down";
fi
if [ $res -eq 0 ]; then
arp -n -i eth1 >> ARPResults
fi
done
我确实看到了一些消息来源表明nmap的,但我试图避免使用的nmap。 – bigbaeng 2012-03-04 02:15:12
任何特殊原因避免它?为什么不使用它,如果它是一个好的程序,并做你想要的? – Wesley 2012-03-04 02:18:40
在我正在做的练习题中,它只推荐使用ping,arp和tcpdump。 – bigbaeng 2012-03-04 02:22:38