From 2200d95ff52279f895e8f2a838d7cfa78b97742b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 20 Aug 2016 02:25:21 +1200 Subject: Add sshi(1) --- bin/sshi | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 bin/sshi (limited to 'bin/sshi') diff --git a/bin/sshi b/bin/sshi new file mode 100755 index 00000000..2f11a61d --- /dev/null +++ b/bin/sshi @@ -0,0 +1,28 @@ +#!/bin/sh +# Print some human-readable information from SSH_CONNECTION + +# Check we have an SSH_CONNECTION variable +if [ -z "$SSH_CONNECTION" ] ; then + printf >&2 'sshi: SSH_CONNECTION appears empty\n' + exit 2 +fi + +# Print the two variables into a subshell so we can chop them up with read +printf '%s\n' "$SSH_CONNECTION" "${SSH_TTY:-unknown}" | ( + + # Read connection details from first line + read -r ci cp si sp + + # Read TTY from second line + read -r tty + + # Try to resolve the client and server IPs + ch=$(dig -x "$ci" +short 2>/dev/null | sed 1q) + sh=$(dig -x "$si" +short 2>/dev/null | sed 1q) + + # Print the results in a human-readable format + printf "%s:%u -> %s:%u (%s)\n" \ + "${ch:-"$ci"}" "$cp" \ + "${sh:-"$si"}" "$sp" \ + "$tty" +) -- cgit v1.2.3