Ruby nmap script to scan IP range for wireless camera and push IP to web server
When our son was born, my wife and I purchased and setup an IP camera in his room. Unfortunately its IP changes periodically and it can be annoying to look it up. I finally gave in and wrote a network IP scan script to find its IP, and copy it to a file on my server in a public location.
First I used Homebrew to install nmap on my Mac:
nmap is a great tool for ip scanning. It provides an option “-O” to look up a system’s operating system, but it requires root/sudo access. This required me to ensure my root user could ssh to my server using an authorized key (ie: no password).
As root I created my RSA SSH key:
And appended the contents of /root/.ssh/id_rsa.pub to my server in file: /home/MYUSER/.ssh/authorized_keys
Here is the script I created to do the IP scan, dump the results to a file, scan for the IP, and push it to my server.
I then cron’d it to run every 5 minutes. edit file: /etc/crontab, added: