Saturday, March 22, 2008

Finding The Fastest Host

I play on Server 3 of Travian UAE, and the domain name s3.travian.ae points at 19 different hosts, and most are slow for me.

The lines below show how to get the server with the lowest average ping time. This assumes the servers will reply to ping requests (only one doesn't), and that you're not blocking ping requests from your end.

for i in $(host s3.travian.ae | awk '{print $4}'); do echo -n "$i:" >> trav.txt \
&& ping -qc5 $i | tail -n1 | cut -d/ -f5 >> trav.txt; done
sort -t: -k2 trav.txt | head -n1
rm trav.txt

Put the result in /etc/hosts and you're all set! This should save you time when querying for DNS, and wouldn't depend on your luck at which server you get (even though Travian employ round robin)

* This is not to be used with any website, since most have MX records (mail server records) and the script above doesn't work in such cases.

* You can remove the backslashes above and write the whole thing in one line. I put on multiple lines to make it readable.

The script is no longer useful since they moved to one server now. Seems like they distribute to multiples during registration period.

2 comments:

Nosayba El-Sayed said...

Can I run something similar but with a syntax of a batch file on Windows?

MBH said...

I suppose you could. I stumbled upon a page with a list of CLI progs for Windows, but I can't remember if similar ones to Linux exist or not.