Hey everyone!

I've been trying to set up a more fool proof time trial thing for my windows application rather than checking the users computer for the time (that can easily be altered). I'm not that experienced with more advanced coding, and I just can't find any code that can do anything close to what I'm looking for either...

I came up with the idea of having a simple little self-updating clock on a website. The website prints just "06/11/2010" on it, but I simply can't pick it up... Everything I've tried only returns the actual html for the clock. It would seem like a simple task to just read what's printed on the page, but apparently it's not...

Is there any way to read what's actually printed on the website? Or somehow read the code "<iframe src="http://free.timeanddate.com/clock/i23768zn/n239/tlse/tt1/tw0/tm3/td2" frameborder="0" width="262" height="22"></iframe>" and get that into a DateTime?

The web clock page: http://kyuubibasher.webs.com/clock.html

Another path I looked into was connecting to a time server of some sort and get the current date that way, but I've never done such things before and I just can't find any decent code to start with...

So far the best I've managed had work is simply reading a .txt file that I've manually inputted the "todays date", but that's just not effective or what I want...

DateTime end = new DateTime(2010, 06, 12);
TimeSpan warning = new TimeSpan();
DateTime now = new DateTime();
DateTime blank = new DateTime();

string result = null;
string url = "http://kyuubibasher.webs.com/time.txt";

//part that needs to be changed somehow
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader tr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
result = tr.ReadLine();
tr.Close();
myResponse.Close();
//end part

try
{
    now = Convert.ToDateTime(result);
}
catch
{
    MessageBox.Show("Error reading from web, shutting down.", "Error!");
    Application.Exit();
}

warning = end.Subtract(now);

time_trial_text.ForeColor = Color.FromArgb(225, 35, 35);
time_trial_text.Text = "Time trial expires in " + warning.Days + " days";

if (warning.Days <= 3)
{
    time_trial_text.ForeColor = Color.FromArgb(225, 35, 35);
}
if (now > end || end == blank)
{
    time_trial_text.Text = "Time trial has expired!";
    MessageBox.Show("Time trial has expired!", "Warning!");
    Application.Exit();
}

Or is there any other way of having the website print the time into something more readable or something? Maybe just a different clock?

Thanks in advance!

If the webpage with the clock is something which you can edit, and if the webhost allows php, asp, or any other language which calculates on the server -
then you could display the time in a much more accessible format. Then you're existing code could work.
The time server sounds like it should be a better idea, but I don't have any experience with that.

The clock comes from http://free.timeanddate.com/, so I can't really edit that code. But I can edit the page it's on.

Checked on php and asp and this host doesn't allow it. It does allow javascript though if that's any use..

I just placed the clock on a free webhost I happened to have, could perhaps find a new free webhost that allows php / asp instead.. All it needs is the tiny amount of bandwith it takes to hold the clock and allow a couple of hundred users to ping it once in a while. Shouldn't be that hard to find..

I know absolutely nothing about php and ASP though : /

Edited 6 Years Ago by Aenonar: n/a

I don't think it's possible to do with javascript, as that will ask the client for their time - precisely what you want to avoid. If you can find a host which allows asp/php that would be the easiest way to go.

Hey,
This can be hacked by editing the hosts file, and redirecting the site to else where. You could also just remove the settings file.

Thought this would be a bit more tricky to bypass than just using the systems clock at least..

But unless they have some outside program to check to what website the program connects to they shouldn't be able to see where it gets the time data from right? And to then hack that host and redirect it somehow..? :/ Should be fairly noticeable if someone fiddles around with the clock.. And all users would suddenly get free time ;>

The whole program is just a single .exe file with everything in it, including the shut off time. So if they somehow get in there to edit the connection website they already have all the code anyways.. Every possible solution could easily be bypassed if they can hack the .exe file :/

What do you mean with removing the settings file?

Edited 6 Years Ago by Aenonar: n/a

As an extra level of security to the webpage approach, you could encode the current date/time with a custom method, and decode it within your .exe file - and compare against that to ensure time wasn't standing still/going backwards. At each check, you could store the newly verified code. Like most things, it's still crackable, but it'd be simple to make it very difficult.

Have a look at Internet time servers.
These are used by Windows (and other OSs) to sync the PC clock.
Looks quite complicated but also seems a bit like what you are trying to do.

You're fighting a losing cause. Just try to create some great software, and pray people will enjoy it enough to pay for it.

This question has already been answered. Start a new discussion instead.