CIDR Calculator for Alfred
Table of Contents
Often throughout my day to day work I find myself looking for a quick CIDR conversion. Something that was lightweight to use and didn’t require switching around my applications. > What was the mask for a /22? How many servers can fit on that mask?
I’ve been running Alfred with the Powerpack for a while and I figured this should be a fairly straight forward process. After some seaches for a CLI tool I came accross whatmask. I then became sorting out how to feed this to Alfred and get useful results.
Requirements #
Install Pre-Requisites #
I recommend installing Alfred + Powerpack and homebrew first. Using homebrew you
can install whatmask fairly easily: brew install whatmask
.
Explanation of Workflow #
Step 1: CIDR Calculator Workflow #
Here is the php code that’s actually running against whatmask. It takes all the lines with useful information and returns them as options for Alfred.
This code uses the Workflows.php class by David Furguson (http://dferg.us/workflows-class/)
Step 2: Clean Up Selection #
The content of that workflow is then piped to
echo "{query}" | sed 's/.*\: \(.*\)$/\1/g'
to return only the necessary data.
Step 3: Print and Put in Clipboard #
That then is passed to Large Type (cause why not?) and then to the clipboard (the actual useful bit).