
Originally Posted by
dante696
But it's not that easy, as everybody here says ;-(
Yeah, this is so hard, it took me 10 minutes to create a bash script that does it.
Code:
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage: $(basename $0) {hostname}"
exit 1
fi
TMP=$(host -t srv _ts3server._udp.$1)
EC=$?
if [[ EC -gt 0 ]] || [[ $TMP =~ 'has no SRV record' ]]; then
echo "No SRV record found for domain $1"
exit 2
fi
WC=$(echo $TMP |wc -w)
echo "Host: $(echo $TMP |awk '{print $'$WC'}')"
echo "Port: $(echo $TMP |awk '{print $'$((WC-1))'}')"
Sample output:
Code:
$ ./getsrv.sh arts.bsrealm.net
Host: ts.bsrealm.net.
Port: 5777