Skip to content

Instantly share code, notes, and snippets.

@zturtleman
Last active May 5, 2023 09:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zturtleman/43b0d1141f52ef31b6a953eb4170a71a to your computer and use it in GitHub Desktop.
Save zturtleman/43b0d1141f52ef31b6a953eb4170a71a to your computer and use it in GitHub Desktop.
Shell script to display raw Quake 3 server info and status responses.
#!/bin/bash
# Shell script to display raw Quake 3 server info and status responses.
# Author: Zack Middleton (zturtleman)
# License: Creative Commons Zero (CC0)
# Note: Default 'classic' netcat doesn't support IPv6 (debian package netcat-traditional)
# so I use the OpenBSD rewrite instead. (debian package netcat-openbsd)
# There is also a nc6 command in netcat6 package...
# netcat arguments:
# -u means UDP
# -q1 means quit waiting for reply after 1 second
NETCAT="nc"
NETCATARGS="-u -q1"
HOST_AND_MAYBE_PORT=$1
HOST=$1
PORT=$2
if [ -z $PORT ]; then
case "$HOST_AND_MAYBE_PORT" in
# IPv6 address with port
\[*\]:*)
HOST=`echo $HOST_AND_MAYBE_PORT | cut -d[ -f 2 | cut -d] -f 1`
PORT=`echo $HOST_AND_MAYBE_PORT | cut -d] -f 2 | cut -c 2-`
;;
# IPv6 address
*:*:*)
HOST=$HOST_AND_MAYBE_PORT
PORT=27960
;;
# IPv4 address or hostname with port
*:*)
HOST=`echo $HOST_AND_MAYBE_PORT | cut -d: -f 1`
PORT=`echo $HOST_AND_MAYBE_PORT | cut -d: -f 2`
;;
# IPv4 address or hostname
*)
HOST=$HOST_AND_MAYBE_PORT
PORT=27960
;;
esac
fi
if [ -z $HOST ]; then
echo "Usage: fetch-serverinfo [host:port]"
echo " [host] <port>"
exit 0
fi
if ! command -v $NETCAT >/dev/null 2>&1; then
echo "Error: Missing netcat ($NETCAT command)"
exit 1
fi
printf "Checking $HOST port $PORT\n\n"
printf "Info:\n\n"
# use cut to remove the "\xFF\xFF\xFF\xFFinfoResponse\n"
printf "\xFF\xFF\xFF\xFFgetinfo xxx" | $NETCAT $NETCATARGS "$HOST" "$PORT" | cut -d"
" -f 2-
printf "\n\n"
printf "Status:\n\n"
# use cut to remove the "\xFF\xFF\xFF\xFFstatusResponse\n"
printf "\xFF\xFF\xFF\xFFgetstatus xxx" | $NETCAT $NETCATARGS "$HOST" "$PORT" | cut -d"
" -f 2-
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment