I was wondering if it were possible to get the current time of a webserver. So for example, I'd like to go on some arbitrary website, and get the current time of the webserver hosting the website.
If it makes a difference, I know some php, html and css. And I know C++, though I doubt that'd help.
Thanks.
<?php
print_r(get_headers("http://www.google.com"));
?>
output:
Array
(
[0] => HTTP/1.0 302 Found
[1] => Location: http://www.google.co.nz/
[2] => Cache-Control: private
[3] => Content-Type: text/html; charset=UTF-8
[4] => Set-Cookie: PREF=ID=099aa9ac8980212e:FF=0:TM=1329099372:LM=1329099372:S=E_PStXZJPIz2ZMm7; expires=Wed, 12-Feb-2014 02:16:12 GMT; path=/; domain=.google.com
[5] => Date: Mon, 13 Feb 2012 02:16:12 GMT
[6] => Server: gws
[7] => Content-Length: 221
[8] => X-XSS-Protection: 1; mode=block
[9] => X-Frame-Options: SAMEORIGIN
[10] => HTTP/1.0 200 OK
[11] => Date: Mon, 13 Feb 2012 02:16:13 GMT
[12] => Expires: -1
[13] => Cache-Control: private, max-age=0
[14] => Content-Type: text/html; charset=ISO-8859-1
[15] => Set-Cookie: PREF=ID=a4441cbc36cea461:FF=0:TM=1329099373:LM=1329099373:S=I6zlXb015nXUM0ht; expires=Wed, 12-Feb-2014 02:16:13 GMT; path=/; domain=.google.co.nz
[16] => Set-Cookie: NID=56=22IthPMv3iR1hlwH0VkhSNq4imnzW4AhPoKM_3boXysAA-Zf4iM0u8Uv6EeV7coLnW91WQqGXyC9AtR4Snh9IG9kSfZRz8pk_X48VwV6UR0eY4c_UrtT8Wdk2zRyNcgR; expires=Tue, 14-Aug-2012 02:16:13 GMT; path=/; domain=.google.co.nz; HttpOnly
[17] => P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
[18] => Server: gws
[19] => X-XSS-Protection: 1; mode=block
[20] => X-Frame-Options: SAMEORIGIN
)
i would not rely on it, what are you trying to achieve?
Make a regular (HTTP) request to the server and see if it returns a date field in the response header. That may be in an adjusted timezone though, so while that would tell you whether the server's clock is set correctly, it doesn't tell you which timezone and hence time the server runs on internally. If the server doesn't return any such value, there's no real way to know.
It's possible allright and you won't need any programming to do it:
- Install a HTTP Debugger like Fiddler and start it to monitor your HTTP traffic.
- Visit the Web Page of the server you want to check.
- Select the entry and take a look at the HTTP Response Headers, you're looking for the one called 'Date' which contains the local time as well as the time zone of the server.
As already mentioned the time can be obtained over HTTP - using the HTTP Time Protocol (HTP) which is available on many systems as htpdate, though since it uses the HTTP Date header usually only has accuracy to the nearest 0.5 second (accuracy can be improved somewhat using multiple servers):
htpdate ntp.org
It is also possible to obtain the time using TLS (which extracts the timestamp from the TLS exchange) tlsdate which can provide better accuracy:
tlsdate -nV ntp.org