This code works perfect when using a machine with only one interface online. (Excluding the loopback of course) But when I have other interface up for vmware or a vpn the output gets mixed up. I know I had this working when I was just reading ip's from files so I know it is not a problem with nmap, even though it feeds back the error. Any help much appreciated.
#!/bin/bash
x=5.21
zero+=( "$(/sbin/ifconfig | grep "inet addr" | awk '{ print $2 }' | sed -e '/127.0.0.1/d' | cut -c6- | sed 's/.[^.]*$//' | uniq)" )
v=`nmap --version | grep "Nmap" | awk '{ print $3 }'`
for i in "${zero[@]}"
do
if [ $v == $x ]; then
one+=( "$(nmap -sP $i.0/24 | grep report | awk '{ print $5 }')" )
sleep 1
else
one+=( "$(nmap -sP $i.0/24 | grep Host | awk '{ print $2 }')" )
sleep 1
fi
done
y=0
length=${#one[@]}
for (( z = 0; z < $length; z++ ));
do
echo -e "${one[$y]}\n"
done
By the way. I have only tested this with nmap 5.00 and 5.21. It may not work at all on other versions.