Network Scans with arp and nmap

Once in a while, I get around running network scans to check what devices and ports are open on my network. The proliferation of IoT devices in my home, combined with lack of VLAN capabilities of my router, has upped my uneasiness in the recent times.

There are two modes of scans I often run

MAC Address scans

All devices on my router have to be manually mac address whitelisted before they are able to connect to either the internet or be used internally. There is also a separate network interface for guests that are barred from the private network.

arp is a handy command that allows listing of all mac addresses on the current network. I use this often for whitelisting and verifying devices.

$ arp -an

nmap network scan

nmap is much more versatile, but also verbose and so I use it sparingly. I do perform network scans in two modes

1. Network namespace scan

The following command scans the entire /24 of the current subnet. It produces a report of all open ports.

sudo nmap -v -O -sS

2. Specific IP scan

For a much more detailed scan, I want to inspect a specific IP address, all its open ports, the services running and potentially the OS as well.

sudo nmap -v -O -A
  • The -A enables OS and service detection
  • Combining this with -T4 allows for faster execution.

Books in 2019

As with 2016, 2017 & 2018, I spent time lot of time reading in 2019. I managed read a total of 28 books, of which a fair amount ended up being science fiction.


Its good to get the nonfiction list out of the way as its pretty short. I enjoyed every single one of them. They were light, informative and useful.

  1. Kubernetes by Kelsey Hightower

  2. The Gene by Siddhartha Mukherjee

  3. The Culture Map by Erin Meyer

  4. The Algebra of Happiness by Scott Galloway

Culture Series

This was the largest series I have ever read. A grand total of 10 books. It is incredible how my perspective changed over the course of this epic, as it went from "I hate this" to "What there isn't any more of this"

  1. The State of the Art by Iain M. Banks

  2. Excession by Iain M. Banks

  3. Inversions by Iain M. Banks

  4. Look to Windward by Iain M. Banks

  5. Matter by Iain M. Banks

  6. Surface Detail by Iain M. Banks

  7. The Hydrogen Sonata by Iain M. Banks

  8. The Player of Games by Iain M. Banks

Revelation Series

  1. Revelation Space by Alastair Reynolds

  2. Absolution Gap by Alastair Reynolds

  3. Redemption Ark by Alastair Reynolds

Scifi (other)

  1. Flowers for Algernon by Daniel Keyes

  2. The Three-Body Problem by Liu Cixin

Hyperion & Endymion series

  1. Hyperion by Dan Simmons

  2. The Fall of Hyperion by Dan Simmons

  3. Endymion by Dan Simmons

  4. The Rise of Endymion by Dan Simmons

Commonwealth Series

  1. Pandora's Star by Peter F. Hamilton

  2. Judas Unchained by Peter F. Hamilton


  1. Sacred Games by Vikram Chandra

  2. Eleanor Oliphant is Completely Fine by Gail Honeyman


  1. Die Trying by Lee Child

  2. Tripwire by Lee Child

  3. And Then There Were None by Agatha Christie

Automated Plant Watering System – Part 3 – the software

This is a follow up to Part 2 and Part 1 of my Mark2 design and build of Plant watering system.


  1. The 3.7v LiPo was unable to deliver the required current of about 350 mA for running 2 motors simultaneously. This lead to the batteries dying out prematurely while being perfectly capable of squeezing out juice for just one motor.
  2. Different plants have different water consumption characteristics. For example with the current setup my Basil plant was thriving while the Coriander plant withered away due to over-watering
  3. The use of a push button without a pull down resistor makes it unusable and therefore less useful.

Fortunately the first two learnings can be incorporated by some software changes. Following are the goals I set out to accomplish in the new firmware and the code to achieve it.


  1. Drive motors independently for different "ON" and interval duration.
  2. Drive motors sequentially, for overlapping run-times/run-intervals. The assumption is its ok if a run is delayed by few seconds.
  3. Support for multiple motors to make the code re-usable for Mark3 prototype.


  1. Motors are configured by the use of an array of MotorConf structs.
  2. whosNext() computes which motor is to be activated. It does so by checking if the delta time from last run exceeded the runtime+waittime.
  3. The watchdog timer is set to wake up the loop every 1 second. However the clock is prescaled to 1/16th the speed. The combined effect should reduce further power consumption.

#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/power.h>

#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)
#define adc_enable()  (ADCSRA |=  (1<<ADEN)) // re-enable ADC

#define led 4
#define MPIN_1 1
#define MPIN_2 0
#define MPIN_EXT_1 3
#define MPIN_EXT_2 2

#define setHigh(pin) pinMode(pin, OUTPUT); digitalWrite(pin, HIGH);
#define setLow(pin) pinMode(pin, OUTPUT); digitalWrite(pin, LOW);

unsigned int lpCntr=0;
unsigned int isOn=0;

struct MotorConf {
  byte pin;
  byte onInterval;
  unsigned short offInterval;
  unsigned long lastUsed;

const unsigned int offInterval_2hours = 2 * 60 * 60; //(60 * 60 * 6) - onInterval; //round it off to 6 hours
const unsigned int offInterval_4hours = 4 * 60 * 60; //(60 * 60 * 6) - onInterval; //round it off to 6 hours
const unsigned int onInterval_2secs = 2; // 2 sleep cycles
const unsigned int repInterval = onInterval_2secs + offInterval_2hours;

struct MotorConf motorState[] = {
  { 1, 2, offInterval_2hours, 0 },
  { 0, 2, offInterval_4hours, 0 },

unsigned int currMotor = -1;
unsigned int maxMotors = 2;

void setup() {

  for(int i=0; i<6; i++) {
    pinMode(i, INPUT);
    digitalWrite(i, LOW);

  pinMode(led, OUTPUT);
  for(int i=0; i<2; i++) {
    digitalWrite(led, HIGH);
    digitalWrite(led, LOW);
  digitalWrite(led, LOW);

  wdt_reset();          //watchdog reset
  wdt_enable(WDTO_1S);  //1s watchdog timer
  WDTCR |= _BV(WDIE);   //Interrupts watchdog enable
  sei();                //enable interrupts

int whosNext() {
  unsigned long currTime = millis() / 1000;
  for(int i=0; i<maxMotors; i++) {
    struct MotorConf currConf = motorState[i];
    if( (currTime - currConf.lastUsed) > (currConf.onInterval+currConf.offInterval) ) {
      return i;
  return -1;

void loop() {
  // Main loop

  int nextMotor = whosNext();

  if( nextMotor >= 0 && nextMotor <= maxMotors ) {
    struct MotorConf currConf = motorState[i];
    currConf.lastUsed = millis() / 1000;



ISR (WDT_vect) {

Future improvements

Mark 2 provided fair amount of learnings. However it was plagued with limitations. Here are some improvmenets planned in Mark 3 re-design

  • Use ESP8266 along with MCP23017 GPIO Expander.
    • ESP8266 will aid in improving the configurability as well as observability.
    • MCP23017 I2C GPIP Expander will dramatic increase in number of IO ports to 16.
  • Ports for 8x Motors, 8x Soil input sensors
  • NodeMCU compatibility along with support for ESP8266 12-E bare IC. The former helps with programming, the later with power consumption.

Starlink satellite tracker

This is my first app that is published on both Android Play Store & Apple Appstore platforms. Despite React Native's brittleness and shortcomings, the productivity I experienced while working with it was phenomenal. I think I might just migrate all my old "pure" Objective-C apps to RN.

Really happy with how it turned out. Am even proud of what my lackluster design skills managed to churn out. The apps were built as a companion to the web version that my friend built (

What do you think?

Getting rid of Alternate Screen

... or simply making the damn terminal content persist when I seek any form of --help or run git diff.

I don't know whoever thought or why they thought that alternate screen was a sane idea is beyond me. I'd do a git diff to check my commits and promptly forget the specifics by the time I get to writing the commit message. Same with the python REPL's help function. The frustration was the kind that builds up like a thousand paper cuts, each seemingly an insignificant occurrence, only day you suddenly find yourself quadriplegic. It doesn't make any sense.

By changing OSX's terminal from xterm-256 to vt100 (Preferences → Profiles → Advanced → 'declare terminal as') I have been delivered into the sweet arms of salvation and from inflicting cuddles of frustration on my cat that has been patient (for a cat) with me through this ordeal.

Am writing this down here because I seem to run into this every few years and promptly forget how I ever managed to get rid of this pest. No more alternate screen, no more, not until this blog and OneNote chose to go away atleast.

Update 1: Oh god, that was terrible in its own right with vim becoming color blind, which sent down on yet another wild goose chase. So the next solution is to configure the pager, which you better hope is less everywhere

export LESS="-iMFXRj4a"

Now the side effect has been magical of man pages and --help now showing up line numbers! I'd call this a success (for now).

Reference and further reading


Stuff I learnt in 2019

I enjoy learning new things, especialy if I am able to either build something out of it or put it to use to improve my life. Here are some things from the top of my head that I managed to learn or start learning in 2019.

Learning new technologies is a never-ending endeavour. I built at least one public-facing hobby project starting from zero with the following:

  • React Native for building iOS & Android apps
    • Published an iOS app with another in the works.
  • Django
    • Built a personal portal to track who I meet, when and how often
  • Dokku
    • How to setup and deploy projects with Dokku
  • VueJS
    • Built few personal utilities using Vue. This completely changed how I view JS
  • Basics of modern JS (ES6)
    • While I wrote a fair amount of Javascript a decade ago, revisiting it made me realise its an entirely new world. Touch basing this has been an uphill battle.
  • Build automation with fastlane
    • Android & iOS
    • React-Native apps


  • Home security
  • Home automation
  • Using VPNs
  • Securing browser stack

Built at least one working thing with each of the following

  • PCB Design
    • Design with KiCad
    • Auto-routing
  • Design for manufacturing
    • BOMs
  • SMD soldering
  • ESP8266s / NodeMCU
    • Programming
    • Components on NodeMCU/Lolin boards
    • Using bare ESP8266
  • ATTiny85
    • Using deep sleep mode
  • Simple Diodes
  • Voltage dividers
  • Voltage regulators
  • Voltage step-up circuits
  • PIR sensors circuits


  • Swimming!
    • Dutch A,B & C diplomas.
  • Health
    • Slowing down and self-care
    • Mental health
  • Taking care of a cat

Food & Cooking
I think I can make a reasonably decent meal out of many of these without having to look at a recipe while making-do in case of missing ingredients.

  • Pasta
    • Creamy Mushroom Pasta
    • Aglio olio
    • Cacio e Pepe
  • Mushroom Risotto
  • Fried rice with mushrooms
  • Fried noodles/Chow mein (with mushrooms)
  • Chinese Noodles
  • Palak paneer (the hand blender way)
  • Spice blends
    • Blending spice mixes for palak paneer & paneer butter masala
  • Soups
    • Bell pepper soup
    • Tomato soup

Automated Plant Watering System – Part 2 – PCB Design and Prototyping

After running the Mark-1 prototype for a week, I wanted to scale up this effort for more of my plants. However efforts to prototype on a PCB blank were a complete mess, so I decided to jump the gun and build Mark-2.



Mark-2 Design Goals:

It was clear that running one MCU per plant was not effective, at the same time I wanted configurability and thus compromises had to be made.

  1. Run on AA batteries or 3.7v LiPo cells.
  2. Control at least 2 Motors
  3. Configure using 2 push buttons with ability to bypass it to use other peripherals such as a soil sensor.
  4. Accommodate both Attiny85 bare IC as well as Digispark.

Bill of materials:

  1. Digispark Attiny85 or bare IC.
  2. 2x NPN Transistors (I used BC547 at hand)
  3. 2x Diodes (I used LEDs due to lack of proper diodes)
  4. 2x 3v Submersible DC Pumps
  5. 1x LED for feedback display
  6. 1x battery pack (min 3v)


Design was fairly similar to earlier prototype with just few more ports.

The design phase involved both schematic design as well as PCB footprint design using KiCad. I made use of hierarchical sheets to "re-use" the schematic design for a single motor.


I used the "Save/Restore Layout" plugin to do the same in PCB mode.



It turned out that the use of a push button without a pull down resistor makes it unusable, due to which am now relying on manual programming.

The duration is programmed to be 2 seconds of watering for every 2 hours, which appears to be adequate for my basil and coriander plants

The code itself was similar to earlier version.

PCB Fabrication

The final step was to export Gerber files, containing Image/SVG representation of all individual layers such as copper front and back, silkscreen for info, soldermask, vias, etc.

A key element of design that I missed during first iteration was the edge cuts which is the SVG layer outlining how the PCB has to be cut.

All the exported files were zipped and sent to pcbway. The fabbed PCBs arrived less than a week later. As shipping was the most expensive part of the process, I might perhaps combine multiple designs into a PCB order so they arrive together.

KiCad Note:

Install plugins by copying files from

  • Source:
  • Destination (macOS): /Applications/KiCad/

Automated Plant Watering System – Part 1

As I finally found sometime at hand, I decided to attend to one of my long standing projects to automate watering of my plants, which have been through stressful troughs of famine and crests of over-watering.




One of the goals were that the system should last long enough while running off a battery. Secondary goals was the use of soil moisture sensors to optimize further.

Bill of materials:

  1. Digispark Attiny85
  2. Common NPN Transistor
  3. 3.7V LiPo
  4. 3V DC Pump
  5. Diode (or LED)


Its a straight forward circuit with the MCU's output controlling the P of NPN Transistor. The Transistor serves to amplify the current as the DC motors are rated at 200mA while Attiny85 is only able to deliver few milliAmps of current.

I modified Digispark Attiny85 by disconnecting the onboard voltage regulator as it consumes ~1mA of current even when the MCU is in deep sleep. As Attiny85 is rated from 2.7v-5.5v the 3.7v LiPo's 4.1v output would be well within the required voltage range.

A DC Motor is an inductor - so when the motor is turned off, the stored energy in the motor flows back as reverse current. It can be powerful enough to damage the MCU, so a diode connected in reverse is needed. Due to lack of components I improvised by the use of a common LED connected in reverse.

Circuit Diagram

The Program

The MCU is programmed to wake up every second via a watchdog timer interrupt. On wake, it checks if it needs to turn on or turn off the output, performs it and goes back to sleep. This means the MCU is asleep even when the motor is running. The ON/OFF state is maintained with the count of wake up cycles rather than milliseconds - this works as each sleep cycle is 1 second.

Digispark's Attiny85's fuses are set at 16Mhz but the input is not exactly stable due the absense of voltage regulatr, this can lead to drift in timekeeping of few minutes per day.

#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>

#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)
#define adc_enable()  (ADCSRA |=  (1<<ADEN)) // re-enable ADC

#define MPIN 1

unsigned int lpCntr=0;
unsigned int isOn=0;
const unsigned int onInterval = 2; // 2 sleep cycles
const unsigned int offInterval = 60 * 60; //(60 * 60 * 6) - onInterval; //round it off to 6 hours
const unsigned int repInterval = onInterval + offInterval;

void setup() {
  for(int i=0; i<6; i++) {
    pinMode(i, INPUT);
    digitalWrite(i, LOW);

  wdt_reset();          //watchdog reset
  wdt_enable(WDTO_1S);  //1s watchdog timer
  WDTCR |= _BV(WDIE);   //Interrupts watchdog enable
  sei();                //enable interrupts

void loop() {

  // Loop counter reset
  if( lpCntr >= repInterval ) {
    lpCntr = lpCntr % repInterval;

  // Loop counter began, so write high
  if( lpCntr == 0 ) {
    pinMode(MPIN, OUTPUT);
    digitalWrite(MPIN, HIGH);
  if( isOn == 1 && lpCntr >= onInterval ) {
    // Reset the output to LOW if we are done
    pinMode(MPIN, OUTPUT);
    digitalWrite(MPIN, LOW);



ISR (WDT_vect) {

Split mp3’s using silence detection

Am listening to audio for practicing dutch comprehension, which essentially consists of a collection of short sentences on repeat. However this audio is available as a single track and for the purpose of shadowing, I wanted individual mp3's.

Enter mp3splt

Install it using brew

brew install mp3splt

Auto detect silence and split

mp3splt -s -d output_folder audio.mp3

This detects the average silence level and uses it to split.


  • -s - Split with auto detection
  • -d - Output directory

Split at specified silence volume

mp3splt -s -p th=-40 audio.mp3


  • -s - Split with parameters specified using -p
  • -p - Input parameters for -s split action
  • th - Silence threshold in dB

Split and remove silence

mp3splt -s -p rm audio.mp3


  • rm - Used in conjunction with -s and -p. Indicates silence is to be removed from the output.

FFMPEG: Combine videos and re-encode

Over the past few weeks, I've taken to recording my Squash games using my Gopro to understand areas of improvement. The video is recorded at 1080p and 60fps, however Gopro splits the video into several large sized mp4 files.

I wanted to combine them together into a single file and re-encoded to reduce the file size significantly and ffmpeg came to rescue.

Combine Files

First order is to combine the files. ffmpeg accepts input text file with each line consisting of the object type ( file  in this case) and the file name. Alternatively it also accepts http and a url as a line item as well.

$ ls *.MP4 | perl -ne 'print "file $_"' > input.txt
$ cat input.txt 
file GOPR4466.MP4
file GP014466.MP4


To reduce file size one can do several things. The easiest is to set the crf flag which indicates "Constant Rate Factor" or the quality of encoding with values ranging from 0 to 51.  0 indicates lossless encoding and 51 the opposite. The default value is 23

$ ffmpeg -f concat -i input.txt -c:v libx264 -crf 28 output.txt


$ ls *.MP4 | perl -ne 'print "file $_"' | ffmpeg -safe 0 -protocol_whitelist "file,pipe" -crf 28 -f concat -i - output.mp4