Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Folks,
I have installed Linux (ubuntu 20.x, 64 bit). I am trying to find out the country. I can figure out timezone. is there any API/config file which I can use? I do not want to use geo-location due to some other constraints.

Thanks in advance!

-- Vikram

What I have tried:

gettimeofday() gives me zone info. But I can not identify specific country from it.
locale can help me but again people can use different language than where they reside.
Posted
Updated 13-May-22 6:48am
Comments
Richard MacCutchan 13-May-22 12:34pm    
No you cannot find the country from the timezone. Timezones extend from the far north to the far south so cover many countries. However, it is far from clear exactly what you are trying to do, or why.
Member 15635207 16-May-22 1:18am    
Thanks. May not be country but can we identify if endpoint is in Europe TZ? I can see that, in same timezone we have list of counties from different continents. So can we add further filter to reach there?

1 solution

You best bet is probably to check the contents of /etc/timezone. That's the default timezone for the system, but even that's not a guarantee. The timezone might be "America/Denver", for example, but the system is actually somewhere in Mexico. There's also /etc/default/locale, which has the system's default locale in it, but once again, just because LANG=en_US.UTF-8, that doesn't mean the system is in the US. As far as I am aware, there's nothing that forces the system to set a country, so you have to rely on the installer to have chosen sane values for locale and timezone. Even using geo-location of the IP isn't guaranteed, as use of a VPN has been known to circumvent location lookup for access to streaming services, for example.
 
Share this answer
 
Comments
Member 15635207 16-May-22 0:48am    
Thanks. May not be country but can we identify if endpoint is in Europe TZ? I can see that, in same timezone we have list of counties from different continents. So can we add further filter to reach there?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900