Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/worldclock/ (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.

like image 729
AVIDeveloper Avatar asked Mar 05 '10 13:03

AVIDeveloper


4 Answers

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.

like image 128
gbjbaanb Avatar answered Nov 09 '22 00:11

gbjbaanb


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.

like image 37
codaddict Avatar answered Nov 09 '22 01:11

codaddict


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.

like image 1
Tronic Avatar answered Nov 09 '22 00:11

Tronic


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!

like image 1
AVIDeveloper Avatar answered Nov 09 '22 00:11

AVIDeveloper