Network Flows Visualization With Nanoleaf Light Panels

I’m a fan of the Nanoleaf light panels! I use them in my office all the time. They provide a great daylight color while I’m in a Webex or training, they react to my music or give a relaxing atmosphere (while you need to concentrate on important stuff). Years ago, when I was working on Solaris systems, I often used the “snoop” (the Solaris version of tcpdump) command with the “-a” parameter to play a sound when some packets matched my filter. Who remembers this feature? Today, it’s the same, I’m often running a tcpdump command with a complex BPF filter, expecting to grab some interesting packets. Why not use my Nanoleaf panels to react to specific flows?

The Nanoleaf controller is connected to the IoT network and can be interfaced with any home automation platform (“Hey Siri, turn on the lights in my office“). But it is also reachable through an API. A Python library is available for this purpose. Let’s try it!

$python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from nanoleafapi import Nanoleaf
>>> nl = Nanoleaf("192.168.254.54")
>>> nl.get_power()
True
>>> nl.get_current_effect()
'Blaze'
>>>

When you need to capture packets with Python, the best library to use is scapy! The script is simple: It sniffs some traffic and, for each received packet, it performs an action on the light panels (if it matches the requirements). The script I wrote works in two “modes”:

  • With random colours – The first time a port of seen, it is assigned to a panel and a random colour is generated.
  • With fixed colours assigned by port – Easier to track the activity on a specific port (ex: you’re expecting an incoming connection on port 8000 and turn a panel in red)

To reduce the calls to the API, the script keeps a list of seen network flows and reacts only with new ones. The syntax is pretty simple:

$ ./pcaplights.py -h
Usage: pcaplights.py [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -i INTERFACE, --interface=INTERFACE
                        Interface (default: "lo")
  -f BPF_FILTER, --filter=BPF_FILTER
                        BPF Filter (default: "ip")
  -c COUNT, --count=COUNT
                        Packets to capture (default: no limit)
  -H HOST, --host=HOST  Nanoleaf Controller IP/FQDN
  -C COLORS, --colors=COLORS
                        Color for protocols (port1=(r,g,b)/port2=(r,g,b)/…)
                        (default: random)
  -v, --verbose Verbose output

Here is a quick video to demonstrate the script:

The good point is that you can sniff on any location in your network and just make the light panels react just in front of you.

The script is available on my Github repository. As usual, the code is working for me but it has not been intensively tested. Bugs are always ahead! 😉

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.