After thinking up a small project to work on, I bought my first Raspberry Pi.. the with a nice little . The intention is to run it headless and have it attached to my home network & log what other devices appear/disappear (we'll use arp-scan to spot them). This would give me the ability to see what devices are connected at any particular time, and also log how long certain devices have been on the network for.
This has multiple uses (all a bit Big Brother-ish, I admit);
- A report can be run to tell how long a device has been running, on what days and in specific time periods.. useful for keeping track of my son's Minecraft habit
- Is anything connecting that you weren't aware of.. you could send email alerts if new devices join that you haven't seen before
- You could extend this project to add the device's current IP to the activity table.. that would be useful for knowing what IP a device might have been given over DHCP at any time
- You could do a JSON web service can be called to see what devices are currently connected.. handy for seeing who's in the house; smart phones usually auto-connect to the wifi when they're in range
I'm sure there are more uses that I've not thought of.
Setting up a fresh Pi
I bought the card for ease of installation.. and chose the Raspbian OS (maybe another distro is more suitable, but I'm a beginner at this!). After it set things up and gave me a terminal, I then needed to get Apache/PHP/MySQL set up.. these are the steps I went through;
1. Set up proxy (optional step depending on your network)..
sudo su cd /etc/apt/apt.conf.d
Create a new file called 10proxy & put in the following...
3. Update packages (are we all up-to-date)
sudo su apt-get update
4. Install arp-scan (this will scan the network to see what's online)
apt-get install arp-scan
5. Install Apache
apt-get install apache2
(check it's working by accessing the server via it's IP.. find that by running ifconfig)
6. Install MySQL
apt-get install mysql-server
Then secure the installation using..
7. Install PHP
apt-get install php5 php-pear php5-mysql service apache2 restart
8. Write a PHP test file
<?php phpinfo(); ?>
You should be able to see the PHP info page when you load it in a browser. That confirms everything is set up.
We need to record which devices we know about together with a friendly name/alias. Then we need to log when devices connect, and when they leave the network. To do this, we'll have 2 tables in our MySQL d/b;
Note; the id field is set to auto-increment.
In the next part, I go into the PHP code that scans the network and populates those 2 tables.