开发者

How to recognize current location in python?

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜