Previous Section  < Day Day Up >  Next Section

Hack 13 Guess the Time Zone of a User

figs/moderate.gif figs/hack13.gif

You're almost off to bed while other users on the channel seem to just get out of bed. That's what happens when IRC is available all over the world, but how can you find out if someone is likely to be awake?

There are several ways to guess the local time of an IRC user, but not all of them are guaranteed to be accurate. The most obvious is to simply ask them what the time is. But what if they aren't around to answer your question? How do you know if they're asleep, not there, or simply ignoring you?

First, you can try to get the user's hostname. You can get it using the /who or /whois command, which reveals information about a user [Hack #15], or maybe you have the hostname already. Most IRC clients will offer you the option of displaying it when a person joins or parts the channel.

In most cases, you'll see a hostname ending with a two-character country code. Take as an example. As you may know, NL is the abbreviation for the Netherlands. Now you can look up the current time there. One way to do it is using the Time Zone Converter ( You can see it in action in Figure 3-3. If you don't know the capital of the country, open the Lookup Time Zone by Country link on the left.

Figure 3-3. Comparing the time in Amsterdam with GMT

There is an obvious problem when you deal with countries that have more than one time zone. Also, with domain extensions like .com or .net, you can't be sure about the user's location. Usually, they point at hosts in the United States, but there are six U.S. time zones in the winter and seven in the summer. Also, there is no guarantee that a .com or .net address even points to somewhere in the United States. Fortunately, there's still a way of finding out where these hostnames belong. For example, you can use the Whois service to check out where the owner of the domain name lives. If that doesn't give any useful information, your last chance is to fetch the Whois information for the IP address the user's hostname points at. To get the Whois information, you can use the whois command available on most Unix machines, or you can look for an Internet Whois service, such as

The whois command can be supplied with an IP address or hostname. For example:

% whois 

will show you something like Figure 3-4. Usually the whois output is very long, so you'll have to read most of it before you find what you're looking for. This screenshot reports on a IP address. From this, you can tell that a * address is usually located in Germany.

Figure 3-4. Whois results for a IP address

By now, you should have some idea of where the user could live, but there could still be more you need to know—for example, some countries have more than one time zone. There's still one last way to find out the user's time zone.

Most IRC clients respond to the CTCP TIME request. They send back the local time for the machine they're running on (assuming the clock is set correctly). For example:

17:25:41 [ctcp(jibbler)] TIME 

17:25:42 CTCP TIME reply from Jibbler: Wed Jan 21 16:25:42 2004

As you can see, Jibbler's machine is one hour behind the time zone I'm in. So now that you know what time zone he could be in, I'll leave the calculations (converting the time into a time zone) up to you.

There is one caveat to this approach. Some people log in from a remote box. This box might be somewhere completely different from where they live. There is only one way to be completely sure about a person's time zone, and that is to ask her (and hope she is telling the truth!).

Since some people don't like to receive CTCP messages (or sometimes they make their IRC client ignore them), it's a good idea to try the methods described earlier first, before falling back to the CTCP TIME approach.

Wilmer van der Gaast

    Previous Section  < Day Day Up >  Next Section