Hamachi Status and IPs without desktop app


So you are using logmein Hamachi, the awesome, easily configured VPN solution that runs networks in gateway and mesh configurations, and lets you see anything from anywhere. You have the desktop app, where you can see your devices easily in a window. You also have it set up on your phone, which allows you to log in to your Hamachi network so you can access your devices.

Problem: You can’t find the Hamachi IPs (or device status) easily when you’re on mobile.

When you’re running the desktop app, to get the Hamachi IP (the special IP that lets you access the device as if it were on your local network), you can see it, and just right click and ‘copy address’. This is not the case, however, when you’re on mobile. So .. you can either:

  1. Memorize that silly IP address and hope that it’s online
  2. Use your desktop app to get the IP (defeating the purpose)
  3. Set a bookmark (not an awful solution)
  4. Find a more elegant solution.

We (obviously) went with 4.

Step 1 : Get and parse the Hamachi data

So this is nothing new (although we did improve it to parse out networks recently). Inside our netfun.py lib, we have a set of functions that will parse the text output from the ‘hamachi list’ command. So hamachi list will output something like this:

 * [187-XXX-002]HomeWork capacity: 2/32, [] subscription type: Standard, owner: xxx@gmail.com
 * 175-XXX-053 innovate alias: not set direct UDP
 * [283-XXX-722]CuPID Network capacity: 11/32, subscription type: Standard, owner: xxx@gmail.com
 * 136-XXX-383 XXXX2 25.XXX.78.58 alias: not set 2620:9b::xxxx:4e3a via relay TCP
 ! 176-XXX-808 linaro alias: not set This address is a lso used by another peer
 179-XXX-373 cupid-xxxx alias: not set
 179-XXX-060 Colin Phone alias: not set
 179-XXX-134 cupid-stevevorres alias: not set
 * 179-XXX-052 MYBOT 25.XXX.112.71 alias: not set 2620:xx::xxxx:7047 direct UDP
 181-XXX-742 colin-home alias: not set
 182-XXX-757 iispace alias: not set

We take this raw data and spit it out into two lists: one containing network dictionaries with their metadata, and another containing a list of client dictionaries with each client’s metadata (online status, etc.). Easy peasy. The function is called gethamachidata(), and is in the netfun lib. It will output something nice:

>>> import netfun
>>> networks,clients=netfun.gethamachidata()
>>> networks
[{'networkid': '187-XXX-002', 'name': 'HomeWork'}, {'networkid': '283-XXX-722', 'name': 'CuPID Network'}]
>>> clients[0]
[{'name': 'innovate', 'alias': 'not set', 'onlinestatus': 'online', 'conntype': 'direct', 'clientid': '175-106-05', 'hamachiip': '', 'connipport': '', 'connprotocol': 'UDP'}]
>>> clients[1]
[{'name': 'XXXX22', 'alias': 'not set', 'onlinestatus': 'online', 'conntype': 'via relay', 'clientid': '136-XXX-38', 'hamachiip': '25.XXX.78.58', 'connipport': '', 'connprotocol': 'TCP'}, {'name': 'linaro', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': 'This addre', 'clientid': '176-XXX-80', 'hamachiip': '', 'connipport': 'lso used by another p', 'connprotocol': 'is'}, {'name': 'cupid-xxxx', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '179-XXX-37', 'hamachiip': '', 'connipport': '', 'connprotocol': ''}, {'name': 'Colin Phone', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '179-XXX-06', 'hamachiip': '', 'connipport': '', 'connprotocol': ''}, {'name': 'cupid-stevexxx', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '179-XXX-13', 'hamachiip': '', 'connipport': '', 'connprotocol': ''}, {'name': 'MYBOT', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '179-XXX-05', 'hamachiip': '25.XX.112.71', 'connipport': '', 'connprotocol': ''}, {'name': 'colin-home', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '181-7XX-74', 'hamachiip': '', 'connipport': '', 'connprotocol': ''}, {'name': 'iispace', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '182-XXX-75', 'hamachiip': '', 'connipport': '', 'connprotocol': ''}, {'name': 'mvbrew', 'alias': 'not set', 'onlinestatus': 'online', 'conntype': 'direct', 'clientid': '184-301-57', 'hamachiip': '25.X.157.62', 'connipport': '73.XX.39.254:35941', 'connprotocol': 'UDP'}, {'name': 'xxxblurg1', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': 'XXX-893-05', 'hamachiip': '25.XXX.45.63', 'connipport': '', 'connprotocol': ''}, {'name': 'Colin Phone', 'alias': 'not set', 'onlinestatus': 'offline', 'conntype': '', 'clientid': '187-XXX-83', 'hamachiip': '25.XXX.25.248', 'connipport': '', 'connprotocol': ''}]

… and so you have a list of networks, and then the clients attached to each of the networks.

Step 2 : Squirt data into webpage

The next part is also pretty easy. We write a little function that runs the above and formats it into a pretty little page. It is in the script hamachidaemon.py, available in the github here. We’d paste it here, but formatting the HTML is a bit of a pain, plus the code will get stale anyway. We do some pretty basic stuff, using jQuerymobile, which we really like, and we get pretty. We add some links too. Typing is for the birds.

Our Hamachi interface. Pretty, with links and networks.

Step 3 : Cron it

As you may guess from the name of the aforementioned script, we run it every so often. We also use this script to double-check that Hamachi is online. So set it up in your cron, and you’ll not only keep yourself online, but also keep your page updated, with links to your hamachi devices! Piece of cake.