Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is it possible to use the same tool to have Ubuntu guess what timezone it is currently in?

This article mentions the feature I'm looking for (just above the second pic): http://www.linuxforu.com/2012/05/ubuntu-12-04-precise-pangolin-review/

share|improve this question
    
Unfortunately, only one of those questions had an actionable/appropriate answer. I guess 64 is better than 55, but I can select answers just for the sake of improving that. –  Bryan Agee Jun 22 '12 at 8:16
1  
Many thanks, Brian. When you have a chance, could you perhaps add comments to those questions/answers as to whats missing, increasing the chances that a good answer will show up in the future? –  izx Jun 22 '12 at 8:20
    
Thanks for the tips--as I have time, I'll go through and update them. –  Bryan Agee Jun 22 '12 at 9:06
add comment

3 Answers 3

Ubuntu uses the ubuntu-geoip package, which queries http://geoip.ubuntu.com/.

You can python-geoip to achieve the same thing:

import GeoIP
geo = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
ip = '200.100.50.0'
print geo.country_code_by_addr(ip)

Sadly, it doesn't work with ipv6 yet.

share|improve this answer
    
I was really hoping that someone might know where that bit of code lives, and if it might be called again.... –  Bryan Agee Jun 22 '12 at 9:07
1  
I found the exact query to get xml: wget -O - -q http://geoip.ubuntu.com/lookup –  Bryan Agee Jun 22 '12 at 9:28
add comment

I believe that it uses your internet connection & ip address to find that information. When I have installed offline it always asks you to select a timezone.

share|improve this answer
add comment
up vote 0 down vote accepted

I decided to download the ubiquity source and dig for it. Greping timezone found the concerned lines, which issue the command:

wget -O - -q http://geoip.ubuntu.com/lookup

and parse the resulting xml.

Rather than load up python or something else, I just wrote a quick bash script that grabs the xml and yanks the timezone out with sed:

#!/bin/bash

# Fetch timezone from Ubuntu's geoip server
TZ=`wget -O - -q http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'`

# Set the current time
cp /usr/share/zoneinfo/$TZ /etc/localtime
share|improve this answer
    
Will that work? I thought /etc/localtime was a binary file? Sure you don't need to do this: –  Jason Livesay Feb 3 at 8:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.