Gavin’s Odd Bits of Code

2012-12-14 (Fri)

Permanent SSH tunnel to OS-X behind NAT

Filed under: Uncategorized — Gavin Brock @ 5:23 pm
Tags: , , ,

I sometimes have an OS-X machine behind NAT that I want to get back to when I’m on the internet.

One way to achieve this is to set up an ssh tunnel on a machine with a known IP.

I put this file in “/Library/LaunchDaemons/com.example.ssh-tunnel.plist”:


<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN””&gt;
<plist version=”1.0″>









In this example, is the globally known server, and remote_user is set up with ssh keys to allow passwordless access.

Now if I ssh to and then ssh to localhost:9922, I get back to the NATed machine.

2011-09-12 (Mon)

csshX 0.74

Filed under: MacOS X,Software — Gavin Brock @ 8:02 pm

Can’t believe it has been nearly a year without a release. This one is mostly bug fixes

–> Download:csshX 0.74 <–

Bug fixes:

  • The “extra_cluster_file” config option now works (great for sharing clusters on DropBox)
  • The –spaces option now ignored on 10.7 since mission control doesn’t have space id’s. You can still use bounds mode to drag to another space.
  • Slaves will move to the same space as the master on retile.
  • Workaround for 10.6 Scripting-Bridge boolean bug is no longer used in 10.7
  • Spaces hacks working reliably on 64bit
  • More spelling fixes

New Features:

  • Connect to one host “n” times with the “hostname+n” hostnames
  • Not really a user feature, but the source code is now under git.

Updates to wiki and macports will come soon..

2010-10-08 (Fri)

csshX 0.73

Filed under: Software — Gavin Brock @ 10:10 am

It’s been a while since I’ve actually pulled together a release, but thanks to everyone’s great feedback and encouraging messages, there are a bunch of new features and bug-fixes that need to get out of the SVN tree.

–> Download:csshX 0.73 <–

New Features:

  • Configurable Ctrl character – if you don’t like Ctrl-A, (maybe it makes using screen to hard?) you can change it using action_key
  • Terminal settings sets – You can choose an alternative terminal settings set (colors, fonts, etc) to use, instead of the default, when opening csshX terminal windows. One use case is to have a settings set without the audible bell, so csshX doesn’t deafen you when you trigger a beep in 20 windows). See master_settings_set and slave_settings_set
  • Hosts files – you can provide a list of hosts to connect to, and optionally remote commands to run, in a file or even piped through stdin. See hosts.
  • More window sorting options – including interleave so you can have your terminals sorted vertically instead of horizontally

Bug fixes:

  • Many spelling corrections – thanks to Mitch Silverstein
  • Reduced memory footprint of the slaves by delaying the loading of modules (15MB per slave, down to 6MB on my box)
  • Fixed spaces support on 64bit machines
  • Fixed layout gaps on multi-monitor systems


2010-05-13 (Thu)

Automatic EasyDNS (or other dynamic DNS) updates from your iPhone

Filed under: Hacks,MacOS X — Gavin Brock @ 3:49 pm
Tags: , ,
2010/10/10: Update: It appaears that the current version of curl on Cydia does not support HTTPS so the script was changed to use wget.
I use EasyDNS to provide name resolution for my domain names. They provide a web based dynamic DNS updates service that allows people with dynamic IP address to update their records to point back to their machines.
I wanted to do this for my (jailbroken) iphone, so I documented my procedure below.

1 – Jailbreak your iPhone

There are plenty of guides on the web about this, and it’s too much to go into here. Try Google.
Once you are jailbroken, continue…

2 – Using Cydia, install the following packages

  • SBSettings
  • OpenSSH
  • cURL (Now using wget, so no download needed)
  • BigBossRecommended Tools

3 – Start SSH and get your IP address

Swipe the top of the screen to bring up the SBSettings menu.
Make sure that SSH is started. If you cannot see “SSH”, goto More -> Set Toggles and enable the SSH toggle button.
Read off the “Data IP Address:” (Should be of the form

4 – Check SSH is working

Check you can connect to the phone over ssh (replace the IP with the one you found above):
computer# ssh root@
The default root password is “alpine”. If you have the default password, change it now, before doing anything else:
iphone# passwd root
Changing password for root.
New password: <type password>
Retype new password: <type password again>

iphone# passwd mobile
Changing password for mobile.
New password: <type another password>
Retype new password: <type another password again>
Now log out of the phone:
iphone# logout

5 – Create the following two files on your computer:

Use your favorite text editor and create the following files (changing the red text to match your account):

while (true); do
IP=`ifconfig  pdp_ip0 | grep inet |  cut -d " " -f 2`
if [ "$IP" != "" ]; then
if [ "$IP" != "$LAST_IP" ]; then
RES=`wget -qO - --no-check-certificate --user=username --password=password "${IP}"`
if [ "$RES" == "NOERROR" ]; then
sleep 60


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
6 - Copy the files to the phone
computer# scp root@
computer# scp easydns.plist root@

7 – Setup permissions and Launchd item

computer# ssh root@
iphone# chmod +x
iphone# sh -x ./
If it runs with no error (it will keep running), you should see (among a lot of debug):
Now press control-c to stop it.
Next, load the launch agent to keep the script running in the background (the script needs to stay running so it remembers your last IP and only updates DNS if it changes):
iphone# launchctl load /Library/LaunchDaemons/easydns.plist
This should complete with no output. You can finally check the script is running
iphone# ps -ef |grep dns
0  1886     1   0   0:00.22 ??   0:00.29 /bin/bash /var/root/

8 – You’re done

Try connecting to your phone by name:

computer# ssh

2010-05-02 (Sun)

csshX 0.72

Filed under: Software,Uncategorized — Gavin Brock @ 8:59 pm

Another production release, like all future releases, this is a 10.5 or newer version.

Bug Fixes:

  • Dragging the bounds window between spaces now works (this is implemented in some embedded Ruby since there was no simple way to do it in Perl).
  • Fixed crash when opening windows to hosts that failed.
  • Reworked the coloring of windows in select/enable/disable mode. Those rare cases when the color was not reset should be fixed.


  • Much faster at opening windows. Some nasty AppleEvents code has helped grab control of the opened window faster.
  • –space command line option (and equivalent config command) to open csshX windows in a particular space.

I now have no bugs, and no user feature requests, so I’m getting bored. ;-)

Feedback welcome..

2010-04-24 (Sat)

csshX 0.71 (and 0.65) released

Filed under: Hacks,MacOS X,Perl,Software — Gavin Brock @ 12:49 pm

For Earth Day – the ecological carbon-free release ;-)

Two new versions of csshX are now available!!

As you may remember, I ran into problems with the release of 64bit Snow Leopard. This was due to Apple dropping carbon support in 64bit perl. The work-around at the time was to run the program using 32bit perl. Obviously this was not the long-term solution.

To control, instead of using the, carbon based, MacPerl module to call the Applescript, the advice was to use the NSAppleScript cocoa class through the PerlObjCBridge perl module. Although this worked great for calling scripts, getting the return value from scripts was extremely messy (NSAppleScript seems only half finished). I then had a look at the ScriptingBridge SBApplication class. This gives me an Objective-C like interface to applescript (although it is much more deceptive than it looks). This was much more suitable and so csshX was changed to use it*.

The downside of this is that 10.4 does not support the ScriptingBridge and so any legacy 10.4 user out there (are there any?) will be stuck on csshX 0.65 forever (0.65 is just a minor bug-fix release to 0.64).

The new csshX 0.70 is a major rewrite of the handling. This appears to make things a lot more responsive, but of course, it may have introduced other bugs. One major benefit is that I can now reliably get handles back for the windows created – this means no more race conditions if you click on any Terminal window while csshX is starting.

Other new features (as way of a bribe to get you to try this) are:

  • Growl messages for certain events. This is experimental, so please let me know if you would like more information, or if it’s too annoying (see the man page for how to disable it).
  • –ssh command line switch to specify the ssh command (handy if you have some wrapper script).
  • Keyboard cursor based move/resize in the bounds-setting mode (in case you hate reaching for the mouse).

You can grab the packages here:

As usual feedback, especially bug reports, are greatly appreciated.

csshX now on Twitter!

Follow brockgr on Twitter

* Nearly.. there is a bug introduced in 10.6 PerlObjCBridge that prevents it calling functions that return boolean values (quite common in Applescript). A bug report has been opened with Apple. In the interim, some of the ScriptingBridge calls are actually being substituted with NSAppleScript ones.

2010-03-30 (Tue)

csshx 0.64 released

Filed under: Uncategorized — Gavin Brock @ 10:57 pm

I have finally cut a new csshX package – a lot of good stuff in this one:

New Features

  • Host and Subnet Ranges – see below
  • Ping test hosts before attempting to connect
  • Sort terminals by hostname
  • Zoom a single terminal to ‘full screen’ key binding
  • Added “enable next terminal” key binding
  • Added “send slaveid” (a guaranteed unique ID) to a terminal
  • Check for users odd shell settings in

Bug Fixes

  • Added the work-around for 10.6 64bit
  • Better window placement (less overlaps)
  • Use the system stty, not macports
  • Better handling of terminal color changes
  • Lots of doc typos and spelling fixes (and probably some new ones)

Get it here:


Hostname ranges

If you have a lot of similarly named hosts, or which to open all hosts in a subnet, hostname ranges will simplify things. Howerver this also allows to open crazy numbers of windows. To avoid this you can use the “ping_test” to make sure a host is up and ssh is working before opening a terminal window.
You can specify subnets using two syntaxes:
This will also work with a hostname, assuming it resolves to a valid IP. If the IP address is not the network address, only that IP and IPs above that address will be used (e.g. will only use 2 ip addresses).
A range is declared in square brackets. Rules are separated by commas. Ranges use a minus-sign. Ranges can be numeric or alphabetic.
Some examples:

csshX now on Twitter!

Follow brockgr on Twitter

2010-02-04 (Thu)

WebSaver 2.5 – 64-bit attempt two

Filed under: Software — Gavin Brock @ 8:33 am

WebSaver 2.5 is now available:

Finally, after patching Unimotion and turning on garbage collection, I have reports that WebSaver is working properly on 64-bit Snow Leopard machines.

As always, I was dependent on the kindness of others for the testing, since I don’t have a 64-bit Apple machine. Please let me know how you get on.

2009-09-06 (Sun)

Websaver 2.3 – Recompiled for 10.6

Filed under: MacOS X,Software — Gavin Brock @ 11:44 am

Just a quick note to let you know that Websaver should now work on 10.6 64bit. The recompiled version is available here:

As you can see, I have moved the source to Google Code, and so any issues can be reported on the issues page.

Cheesy disclaimer: I don’t have a 10.6 64bit capable machine for testing :-( . Please let me know if it works.

2009-06-18 (Thu)

csshx 0.63 released

Filed under: Software — Gavin Brock @ 11:59 am

Bug Fixes:

  • User@host:port style names should work properly now
  • -x -y arguments documented properly
  • More meaningful warnings if your configured clusters are badly declared

New Feature:

  • “f” in bounds mode, now resizes csshX to take the full screen.

Get it here:


Next Page »

Create a free website or blog at