-
-
Save djblazkowicz/7e0b99a5e6a5ff76ebcfb48c95999f2f to your computer and use it in GitHub Desktop.
Shell script to display raw Quake 3 server info and status responses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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