Skip to content

holding them accountable

holding them accountable published on No Comments on holding them accountable

Sometimes I do things that my girlfriend looks at and replies, “Not everyone can do that”.

Well, I’m going to prove her wrong.

We’re going to build a network monitoring system using a Raspberry Pi.
First things first, you need a Raspberry Pi, and the relevant accessories. Choose a vendor or retailer, they’re pretty easy to come by nowadays.

Next, you’ll want to image it with MiniBian, a super lightweight debian-based stack. It’s literally the smallest full debian OS image I’ve found for the rPi. Minibian Page

Minibian boots with SSH enabled by default, so make sure you boot this little guy up behind a firewall. Then, change the password from the default.

After the password has been changed, be sure to update everything.

apt-get update
apt-get upgrade -y
apt-get install rpi-update

This should have the repos, packages, and firmware up to date on what is now a tiny SSH server.

Next, we’ll install nginx or Apache2. Again, your call.

apt-get install apache2
apt-get install nginx

It’s entirely up to what you prefer as a sysadmin.

Then, we’ll add a dash of PHP.

apt-get install php5

Lastly, we have a bit of actual code to write. Little more than a few bash scripts and some PHP to display the results.

#RESULTS=`python ./ | set 's_[:]_,_g'`
PINGRESULTS1=`ping -c 10 | head -n 15 | tail -n 1 | sed 's_[/=]_,_g'$
echo -e $TSTAMP "," $PINGRESULTS1 >> /var/www/html/DEV_networkcheck.csv

For those of you clever enough to read bash, this is pretty easy. It creates a couple of variables to timestamp and store the results.
Then, it uses standard command-line stuff, like ping, head, tail, and sed to slice down to just the statistics at the end of a ping test.
Lastly, it echoes those results and the timestamp to a file.

The final piece of the puzzle, is the PHP script to display that resultant file as web content.

echo "<meta http-equiv='refresh' content='300'>";
echo "<html><body bgcolor='#dddddd' text='#DDDDDD'>";
echo "<title>Service Quality Monitoring</title><BR>";
echo "<font color='#000000'>";
echo "<BR><table style='color:#dddddd' bgcolor='#222222' border=0 cellpadding=5$
$f = fopen("DEV_networkcheck.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td bgcolor='#333333'>" . htmlspecialchars($cell) . "</td$
echo "</tr>\n";
echo "\n</table></body></html>";

Now, I hear you all saying… “But floz, ICMP ping is just one test we can do!”. You’re absolutely fucking right it is. This is one of those “teach a man to fish” situations, though. Creating an automated network trace, bandwidth test, or other diagnostics beyond this is an exercise ENTIRELY left to the reader.

For reference, I offer the single most useful tool to any hacker: Google.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.