2
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
Can you do a DHCP request and from that gather an IP and network mask? (Though doing that from user mode might be interesting). – Hennes – 2013-02-27T22:45:29.723
No, I am running this script as root. I'll be fine with whatever you can think of – Sirens – 2013-02-27T22:48:43.503
1@TheDeveloper I think he means user mode as opposed to kernel mode. Kernel mode is lower-level and gives much more direct hardware access (as you could guess from the name), and is generally used by the kernel and drivers. User mode is more restricted for stability reasons - a kernel mode bug will crash the system. Even though you're
root
, you're still in user mode. – cpast – 2013-02-27T23:02:39.9071is this a fantastically elaborate way of doing `nmap -sP 192.168.0.1/24' ?? – Sirex – 2013-02-27T22:56:51.390
No. I need this to work without installing stuff. Is there anyway you can run a command for each IP that is up? – Sirens – 2013-02-27T22:58:54.273
Well, DHCP is almost always done in user mode... On the other hand, it does require root privileges, to bind to the low ports. – user1686 – 2013-02-28T02:01:40.450