Jump to content

Ping server for precise time


Recommended Posts

I need a way to ping a server for an exact time, the Microsoft time keeping server basically or whatever

I need the time stored in a variable

I need it to be absolutely perfect, which (I'm not sure) may also include getting a ping route time or whatever and subtracting that many ms from the time value it returns to make sure it's absolutely perfect

Anyway

I need something that simplified looks like this

(Script to ping Micrisoft time server and get perfect time)

$time = (perfect time)

$ping = (total ping time)

$realtime = (time - ping)

Link to comment
Share on other sites

Wouldn't NTP take that into account?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This might have what you need.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Wouldn't NTP take that into account?

No. The time server has no way of knowing how long the routing will take.

My confuzzled mind thinks that the math is incorrect though. In my mind the route time should be added to the NTP time and in fact I think it should be one half of the time. Route times should be the total time both ways.

No matter what; precision is going to be dependent on a few factors and will never be in the picosecond range.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I'm sorry but I still really don't understand that script

I'm still really new to all of this

Which parts of this code are the ones that would simply result in having a variable equal to the time?

; Set Date and Time from Internet
; this code is derived from:
; http://www.autoitscript.com/forum/topic/43079-ntp-c-to-autoit-conversvion/page__view__findpost__p__765481

#include <Date.au3>

$ntpServer = "de.pool.ntp.org"
$socket = False
OnAutoItExitRegister("Cleanup")
Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc ;==>Cleanup

While Sleep(1000)
    UDPStartup()
    $socket = UDPOpen(TCPNameToIP($ntpServer), 123)
    If @error Then
        UDPShutdown()
        ContinueLoop
    EndIf
    $timer = TimerInit()
    UDPSend($socket, MakePacket("1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"))
    If @error Then
        UDPCloseSocket($socket)
        UDPShutdown()
        ContinueLoop
    EndIf
    $data = ""
    While $data = ""
        $data = UDPRecv($socket, 100)
        Sleep(100)
    WEnd
    $diff = TimerDiff($timer)
    UDPCloseSocket($socket)
    UDPShutdown()
    ExitLoop
WEnd


;MsgBox(0, "UDP DATA RAW", $data)
$unsignedHexValue = StringMid($data, 83, 8); Extract time from packet. Disregards the fractional second.
;MsgBox(0, "UDP DATA", $unsignedHexValue)

$value = UnsignedHexToDec($unsignedHexValue)
$TZinfo = _Date_Time_GetTimeZoneInformation()
;$TZoffset = $TZinfo[1] * - 1
$UTC = _DateAdd("s", $value, "1900/01/01 00:00:00")

If $TZinfo[0] <> 2 Then ; 0 = Daylight Savings not used in current time zone / 1 = Standard Time
    $TZoffset = ($TZinfo[1]) * - 1
Else ; 2 = Daylight Savings Time
    $TZoffset = ($TZinfo[1] + $TZinfo[7]) * - 1
EndIf

;~ Extracts the data & time into vars
;~ Date format & offsets
;~ 2009/12/31 19:26:05
;~ 1234567890123456789 [1 is start of string]

$m = StringMid($UTC, 6, 2)
$d = StringMid($UTC, 9, 2)
$y = StringMid($UTC, 1, 4)
$h = StringMid($UTC, 12, 2)
$mi = StringMid($UTC, 15, 2)
$s = StringMid($UTC, 18, 2)

;~ MsgBox(0,"",$m & "/" & $d & "/" & $y & " " & $h & ":" & $mi & ":" & $s) ; Visual test of obtained date

;~ Sets the new current time to the computer
$tCurr = _Date_Time_EncodeSystemTime($m, $d, $y, $h, $mi, $s)
_Date_Time_SetSystemTime(DllStructGetPtr($tCurr))
MsgBox(262144, "", @LF & $diff & " Milliseconds roundtriptime" & @LF, 10)


;**************************************************************************************************
;** Fuctions **************************************************************************************
;**************************************************************************************************
Func MakePacket($d)
    Local $p = ""
    While $d
        $p &= Chr(Dec(StringLeft($d, 2)))
        $d = StringTrimLeft($d, 2)
    WEnd
    Return $p
EndFunc ;==>MakePacket
;**************************************************************************************************
Func UnsignedHexToDec($n)
    $ones = StringRight($n, 1)
    $n = StringTrimRight($n, 1)
    Return Dec($n) * 16 + Dec($ones)
EndFunc ;==>UnsignedHexToDec
;**************************************************************************************************
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...