A helpful script for simplifying connections to servers and devices on your network.
Add the script as a source file in your shell prompt, exporting any config variables, such as with lines similar to this:
# Tab Sorcery
export SORC_GEOM_RDP="1600x900" #(Optional) Sets the window resolution for RDP connections
. $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user
Arguments for the script are required, in the following order:
Scan Domain (example.com)
Nameserver address (127.0.0.1)
Default username (bob.user)
Important: While a hostname may be used in lieu of an IP address for the DNS server used by this script, it is not advised. If this hostname fails to resolve, it may have unintended consequences that could be avoided by using an IP address. There may be an update at a later time to enforce a sanity check to prevent this, but this is not yet in place.
Once done, all hostnames in the DNS zone should be available for SSH/Telnet/RDP by a tab-completable alias of just the hostname (in new shell sessions).
Options can be configured as exported variables, set in your shell RC files before calling the tab-sorcery script itself. So far there are two options:
This option sets the resolution of your Windows RDP connections. If left unset or an invalid value is detected, the default is 1600x900. Example:
export SORC_GEOM_RDP="1280x720"
This option supplies the path to a plain text file containing a list of hostnames and passwords in the following format:
hostname=password
If this option is provided, hosts marked as Windows hosts will check this file for a password and pass it on to the alias for the host in order to make logging into Windows almost as painless as *nix hosts. This feature should be considered temporary and used only at your own risk. This is a very insecure thing to do, and the intent is to replace this later with LastPass support or similar instead, and was added mostly as a personal exercise.
To configure, once you have your password file set up, just export the location as a variable in your shell RC before sourcing the Tab Sorcery script like so:
export SORC_PASS_FILE="$HOME/.some_file"
Here is a full example utilizing all available options. Please note that only the last line, beginning with a dot, is absolutely required.
export SORC_GEOM_RDP="1280x720"
export SORC_PASS_FILE="$HOME/.some_file"
. $HOME/git/tab-sorcery/tab-sorcery.sh example.com 127.0.0.1 bob.user
You'll likely want to create a DNS zone specifically for this script for better control over the hosts included. I would recommend using a TLD not normally available, to be sure you don't have any overlap with existing DNS names. This domain doesn't need to be publicly queried, and actually it's probably in interest of security if it isn't.
There are 4 types of hosts supported right now, which are identified by accompanying TXT records. The default (no TXT record) is to use SSH with your normal configured username. The other 3 types require a TXT record to match the A record of the host, and have the following properties:
TXT value | Effect |
---|---|
[none] | Log in as configured user over SSH |
logroot | Log in as 'root' user over SSH |
windows | Log in over RDP (rdesktop) |
cisco | Log in with a generic telnet connection |
As an example, let's assume you create the zone "not-a-real.lan" and you have 5 hosts, known as host1.not-a-real.lan through host5.not-a-real.lan. Let's assume you create the following entries (BIND format shown):
$ORIGIN not-a-real.lan.
host1 IN A 10.0.0.1
host2 IN A 10.0.0.2
host3 IN A 10.0.0.3
host3 IN TXT "cisco"
host4 IN A 10.0.0.4
host4 IN TXT "windows"
host5 IN A 10.0.0.5
In this case, the script will create aliases called host1 through host5.
Hosts 1, 2, and 5 will connect with, for example, ssh -t your.username@10.0.0.1
The host3
alias is tagged with a TXT record for cisco, so it will be: telnet 10.0.0.3
host5
is tagged as a Windows host, so it will use: rdesktop -g 1600x900 -u your.username 10.0.0.5