Handling Telnet URLs with Iceweasel (Firefox)

(Last updated: 2010-10-20)

Disclaimer

The information below is accurate to my knowledge, however I provide no guarantees to this effect and consequently accept no liability whatsoever for any bad things that may happen as a result of the reader using this information in practice. Use at your own risk. Oh, and backup your data while you're at it.

Introduction

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.

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

The problem

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.

Instructions

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://" 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

Conclusion

Hopefully this works and you can now launch telnet sessions from your browser.

As always, constructive feedback is welcome.

References