I am making a network scanner that will work on any network. This is my code so far
fd=$(date +%m%d%y%H%M%S)
echo -e "IP$fd\nReport of IP addresses on this intranet, test started at \n$(date)\n\nThe following IP addresses were found:" > IP$fd.txt
echo -e " Okay. Mind you, this could take a couple of minutes.\nI'll be scanning all 254 possibilities between 192.168.1.1 and 192.168.1.254\nI will ring the system bell when I am done.\nHere we go..."
for i in 192.168.0.{1..254}
do
echo "scanning $i"
if [ "$(ping -q -c1 $i)" ]
then
echo -e "AHA! Got one! ---- $i is up!"
fi
echo "END SCAN"
done
echo -e "That's all I got.\Test completed at\n$(date)\n" >> IP$fd.txt
echo -e \\a
echo -e "Your report is IP$fd.txt, and this is what it says:\n"
exit
Except the problem is that this will only work if your IP range is 192.168.0.1-255. It won't return anything if the ip is 10.10.10.1.
Is there anyway I can get the users network range and apply it to my script?
Edit: I am running as root
root
, you're still in user mode.