Retrieve time from the internet (bypassing PC clock)?
For my MFC/C++ unmanaged time-limited software needs, I'd like to get a GMT/UTC time-stamp from the internet (instead of relying on the PC clock time that can be easily changed).
I already though about parsing the line "Current UTC"... line from http://www.timeanddate.com/world开发者_Go百科clock/ (I think port 80 is more likely to be open than others) but I don't know how reliable this URL is...
Please share with me your pros/cons or different ideas on this.
Thanks.
Use a SNTP (Simple Network Time Protocol) to get the time from an internet atomic clock.
There's a few libraries available on the web - here's one for MFC on codeproject.
Looks feasible and this is widely done.
Scraping of timeanddate.com can break if the site decides to change its HTML. Even a slight change in the HTML can break your scraper.
I would suggest you use a web service like earthtools. You'll have to pass the necessary arguments(latitude and longitude etc) in the URL and the response is XML which you can easily parse.
Make your program better instead of wasting time trying to protect it. Any such protection that you can do will be circumvented easily. If you insist, you can run the software on your server, as this is the only way to actually enforce such limits.
Well, To conclude:
My app contains an offline database that is updated once a day from the intranet.
I'd like to shred this database if it was not updated over a week and that's why I'd like to try and reduce the possibility of someone just changing the PC clock backwards.
I am fully aware of the fact that there are power users that could block my app from getting internet time in 20 different ways, but I'm trying to do the best I can in software (a hardware solution, e.g. a dongle, is an overkill for me).
Since I want to have a port 80 solution, I'll adopt codaddict's solution (earthtools) and will sample the PC clock otherwise.
Thanks for all the replies!
Hmmm. Interesting. You are basicly trying to use the Internet as a dongle.
If you truly need this kind of "protection" over your software, you should perhaps consider getting a true dongle with a real-time clock in it, like HASP. Of course either soltion is going to be trivial to get around for a decent hacker with a disassembler.
Generally I think it is better to open your software up and try to live off of fixes, mods, and support.
The answer lays within your question... Go to https://www.timeanddate.com/ and look for "API", you will find this page: https://www.timeanddate.com/services/api/ Detailed instructions: https://services.timeanddate.com/api/packages/time.html Using their API you send a request and receive an XML or JSON response. It cost you $150 per year but that's the professional way of doing it and since your purpose it to charge money for your software it makes sense.
National Institute of Standards and Technology (NIST) Internet Time Servers
References https://www.nist.gov/pml/time-and-frequency-division/time-distribution/internet-time-service-its
https://tf.nist.gov/tf-cgi/servers.cgi
精彩评论