Handling Telnet URLs with Iceweasel / Firefox

I needed to find a way to launch telnet sessions from a webpage URL using the Iceweasel (Firefox) browser on my Debian GNU/Linux workstation. This simple task proved to be quite time consuming, as a lot of the HOWTOs out there were (at the time of writing) relying on obsolete information.

By default if you try an open a link similar to telnet://name on Debian using Iceweasel you will get the following error message:

Firefox doesn’t know how to open this address, because the protocol (telnet) isn’t associated with any program.

The steps below should work in Iceweasel/Firefox 3.5+.

Browser configuration

These have been mostly copied from the mozillaZine Knowledge Base page on the subject:

  • Type “about:config” into the Location Bar (address bar) and press Enter.
  • Right-click → New → Boolean → Name: network.protocol-handler.expose.telnet → Value → false
  • Next time you click a telnet:// link you will be asked which application to open it with – use the script below, or write your own.

Script to open a console window

This script assumes the URL will be in the following format: telnet://name-or-ip:port.

#!/bin/sh

URL=`echo "$1" | sed 's#telnet://##'`

HOST=`echo "$URL" | awk -F':' '{print $1}'`
PORT=`echo "$URL" | awk -F':' '{print $2}'`

x-terminal-emulator -e telnet $HOST $PORT &

To use this script copy the above to a file, save it and then make it execuable. For example:

vim ~/scripts/telnet_launcher.sh
chmod +x ~/scripts/telnet_launcher.sh

References

Register protocol