Tuesday 21 July 2015

How to get the IP address of a Mac

Every time you connect a new network adapter to a Mac, you get a new Ethernet device configured to your computer. This is of both logical and expected, but it means that you can't really tell what the name of your currently active network interface is. This makes things like checking your IP address a bit cumbersome.

And here's a shell script to remedy:


#!/bin/bash
interface=$(route get default| awk '/interface: / {print $2}')
ipconfig getifaddr $interface

This will only return the IP address of your default NIC. If you have more than one active network interface, you'll have to take the long route :)

Thursday 25 June 2015

I made an Internet Button

Along comes a few days of solo summer vacation and i’m off to the countryside. So what can a man do out in the wild? Hack.

An Internet Button is a button which, when you press it, makes something happen on the Internet. It’s the Internet of things equivalent of a Hello, World! program, and i made one yesterday built on the Proton Core platform.

A Core is basically an Arduino compatible microcontroller with a Wi-Fi chip slapped on, and a cloud environment to support the whole shabang. I’ve had two of these Spark Cores (as they were known then) for well over a year now, since backing them on a Kickstarter campaign, but i’ve never really got around doing anything sensible with them. The problem was always that the Wi-Fi connection dropped after some time and then the program crashed. So i borrowed my chips to a couple of colleagues (on houm.io) who used them to draw attention and open a door. Eventually i got them back, and they were left to gather dust in my geek cave.

Since the new Particle Proton chips are finally going to ship now, i’d read a bit on the documentation and decided to give my Cores another spin. The results, along with the instructions on how to get the button on the Internet, are on Github.

Friday 13 February 2015

Create an encrypted USB disk from the command line

This recipe will

  • create a semi-random disk name and a fairly safe password
  • erase and encrypt the disk diskdevn (use diskutil list to figure out which one it really is or face potentially unfavourable consequences)
  • save the credentials into the file USBdisks.db in your home directory (or where-every you point the variable passfile

code

# (c) Robin Laurén 2015
# License: BSD 2-clause
#
diskdevn=/dev/disk4 # nopd: you may want to edit this one
passfile=~/USBdisks.db
diskname=USBdisk-$(pwgen -B 4 1)
diskpass=$(pwgen -s 16 1)
diskutil partitionDisk /dev/disk4 1 GPT jhfs+ $diskname 100%
diskutil cs convert $diskname -passphrase $diskpass
echo "$diskname $diskpass" >> $passfile

Create an encrypted USB disk from the command line

Oops. This post was published in markdown and now i can't change that. See next post for correct formatting :)