I received a Raspberry Pi for Christmas and I hadn't found a good use for it yet - until now! Well, sort of. I at least found something kind of fun to do with it...as long as your definition of fun is very loose.
I've been using RabbitMQ at work, and I found someone's post about running RabbitMQ on their Raspberry Pi. "A ha!", I thought. "I'll load interesting messages onto channels, and then I can write an Android app that will fetch the messages. It will be so amazing!" The problem is that I couldn't think of what type of data I would want to get. I ended up deciding to capture all IP addresses on my home network using nmap.
I installed RabbitMQ on the Raspberry Pi by following someone's blog post (very well written!), and then added a user and virtual host. I then wrote a script and some Java code to log all of the IP addresses on my local network. We have a number of devices that connect and disconnect throughout the day, so there would be enough of a change as time goes on to make it interesting.
The script runs nmap to get the network info, and then it calls some Java code that publishes the info to a RabbitMQ channel. I decided to use Java because it was the easiest for me to write the code. I might redo the code in Python once I get some experience with Python.
The nmap command is pretty straight forward:
sudo nmap -oX myscaninfo.xml 192.168.1.1/24
sudo nmap -oX myscaninfo.xml 192.168.1.1/24
The -oX parameter tells nmap to output the results in xml format.
The IP address with the CIDR (Classless Inter-Domain Routing) value at the end (192.168.1.1/24) specifies the IP addresses to scan. In the example above, it would mean the following:
192.168.1.1 is the starting IP address. We would then mask the address with 24 1 bits => 255.255.255.0. 255 is what 11111111 equals (-1 due to 0 based index). That means that we would want to view all IP address that are in the unmasked range - 192.168.1.1 to 192.168.1.255.
The Java code parses the XML and pulls out all the address info. It then pairs the IP address with a MAC address, and publishes the data to RabbitMQ.
The next step will be to create an Android app to read from the channel and display the data.
No comments:
Post a Comment