views:

53

answers:

1

My client has two offices in Germany and USA and a python program should recognize the office location. What will be the most elegant way to implement this? It only have to recognize the country. Furthermore it also could happens that there will be no permanent internet connection. The program works on windows but the solution should be os independent.

Any suggestions? Thanks

+4  A: 

AFAIK, there's no elegant solution. You can make educated guesses, but then, take this example: I unplug my laptop in Germany and go to the USA. I plug it in the US office - the regional settings are the same, the time zone didn't change, now what?

Things from which you can make a guess:

  • regional and language settings (but a German in the USA can be using de_DE)
  • time zone (but are we in NYC or in Brazil? same TZ offset; in your case, (PDT/EDT) and CET is different enough)
  • internal IP address (assuming your offices have different internal addressing (e.g. "10.5.20.0/24 - Germany, 192.168.4.0/24 - USA"; what of the VPNs, what about unconnected devices?)
  • external IP address (if you need accuracy on the scale USA/Europe, this is passable; of course, VPNs mess this up, and question says external connectivity may not be available)
  • keeping a list of which computer is where (messy and hard to maintain)
  • keeping a list of which user is where
  • remembering where this computer was on last program start (and whether it was corrected manually)

By assigning a score to each of these things, and checking for each, you could get a probability score where the computer is. You might get some incorrect guesses though, so make a manual override, too.

The combined score might be quite accurate in the general case; what you need to do is find the edge and corner cases, then find some way to identify those.

Piskvor
Thats true! :( Up to now I have stick to computer name since they are different. But who knows it could happens that they will be unified in the future ...
koleto
good point. i think in this case dropdown list allowing user to change location manually (and maybe store in some preferences) is the best way.
Lukasz Dziedzia
Yep! I am going to implemented in this way in the next time ...If I am sure that the time.timezone will give positive value in USA it could solve partially my problem?
koleto
@koleto: Yeah, each can give you some confidence on where you are; TZ is a pretty good indicator. EDT should be GMT-06, CET GMT+1 (or GMT+2 in DST). Misconfigured computers or travelling laptops could be set to anything - this may be a major problem or none at all, depending on how common those are.
Piskvor
I think it is a good starting point ... Thanks again!
koleto