Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quickly tells the Debian version running on a given host. Requires ssh server enabled.
#!/bin/sh
#
# Tells the Debian version reading the OpenSSH banner
# Requires OpenSSH to be running and ssh port to be open.
#
# Usage: $0 <hostname>
#
# Cosimo, 23/11/2011
HOST=$1
if [ "x$HOST" = "x" ]; then
echo "Usage: $0 <hostname>"
fi
OPENSSH_BANNER=$(echo "\n" | nc ${HOST} 22 | head -1)
#echo "OPENSSH_BANNER=$OPENSSH_BANNER"
IS_SQUEEZE=$(echo $OPENSSH_BANNER | egrep '^SSH-.*OpenSSH_5.*Debian-6')
IS_LENNY=$(echo $OPENSSH_BANNER | egrep '^SSH-.*OpenSSH_5.*Debian-5')
IS_ETCH=$(echo $OPENSSH_BANNER | egrep '^SSH-.*OpenSSH_4.*Debian-9')
# SSH-2.0-OpenSSH_5.1p1 Debian-5
# SSH-2.0-OpenSSH_4.3p2 Debian-9etch3
# SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze1
#echo "Squeeze: $IS_SQUEEZE"
#echo "Lenny: $IS_LENNY"
#echo "Etch: $IS_ETCH"
if [ "x$IS_SQUEEZE" != "x" ]; then
echo "$HOST is Debian 6.x (squeeze)"
exit 0
fi
if [ "x$IS_LENNY" != "x" ]; then
echo "$HOST is Debian 5.x (lenny)"
exit 0
fi
if [ "x$IS_ETCH" != "x" ]; then
echo "$HOST is Debian 4.x (etch)"
exit 0
fi
echo "I don't know what $HOST is."
echo "Here's the openssh banner: '$OPENSSH_BANNER'"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment