Cheap IOT By Hacking Routers

October 27, 2015

As I previously blogged about, we have a Raspberry Pi at BigPanda that opens our office door.

We even created an Android widget to open the door from the outside, so it’ll be as easy as possible.

ALAS, this was not enough, Noam Shemesh (the mighty) felt that the effort of actually taking out your mobile phone when approching the door is tedious.

IOT to the rescue!

We needed to have some kind of sensor that we’re approaching the door from the outside, and of course be secure (ish).


The routers have a device list, now if only their API was documented and open.


Oh well, time to improvise.

After sniffing the network requests from the admin GUI, testing a bit with curl, we had a way of knowing not only what clients are connected, but also retrieve their MAC addresses, and the last time the devices connection changed.

We wrote a swift hack in node, which pulls the device list and manage a state of connected items, and checks if there’s any new connections for whitelisted MAC addresses.

If so we open the door.


var request = require('request');
var _ = require('lodash');
var Promise = require('bluebird');
var routers = ['XXX.XX.XX.XXX', 'YYY.YY.YY.YYY'];

var whiteList = ['FF:FF:FF:FF:FF:FF', 'AA:AA:AA:AA:AA:AA'];

var devices = {};

function getOptions(router){
  return {
    url: 'http://' + router + '/JNAP/',
    headers: {
      'X-JNAP-Authorization': 'Basic WHYOWHYBASE64PASSWORD=',
      'X-JNAP-Action': '',
    json: [{"action":"","request":{"sinceRevision":0}},{"action":"","request":{}}]

var openDoor = function(){

function getDevicesFromResult(body){
  return _.chain(
          return device && device.connections && device.connections.length > 0;
          return {
            MAC: device.knownMACAddresses[0],
            name: device.friendlyName,
            lastChange: device.lastChangeRevision
          return whiteList.indexOf(device.MAC) >= 0;

function handleGotOnline(device){
  console.log(device, 'got online');

function handleDevices(onlineDevices){
  _.each(onlineDevices, function(device){
    if (!devices[device.MAC]){
      devices[device.MAC] = device;

    var theDevice = devices[device.MAC];
    if (device.lastChange > theDevice.lastChange){
      devices[device.MAC].lastChange = device.lastChange;
  setTimeout(promptRouters, 1000);

function callback(response) {
  return getDevicesFromResult(response.body);

var postPromise = Promise.promisify(;

function promptRouters(){
  Promise.all(, function(router) {
        return postPromise(getOptions(router))
        var onlineDevices = _.flatten(results);
        console.log("got results", onlineDevices.length);

comments powered by Disqus