LogicMachine Forum
NTP Client Details - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: NTP Client Details (/showthread.php?tid=6133)



NTP Client Details - CHOUAIBOU - 30.09.2025

Hi,
I am using LM as NTP Server to sync Date & Time of connected NTP clients. I need a script to log NTP data exchange details from any device configured as NTP client and connected to the LM NTP server.
There is are available scripts in the forum, but they are used for logging the NTP data exchange between LM as NTP client and a remote NTP server.

Thanks,
Chouaibou.


RE: NTP Client Details - admin - 30.09.2025

Disable both NTP server and client in system config. Create a resident script with sleep time set to 5 seconds. You can replace region (europe) with 2-letter country code (de, fr, etc) for more precise time updates.
Code:
reg = 'europe'
cmd = '/usr/sbin/ntpd -ddd -l -n -p 0.%s.pool.ntp.org -p 1.%s.pool.ntp.org -p 2.%s.pool.ntp.org -p 3.%s.pool.ntp.org 2>&1'
cmd = string.format(cmd, reg, reg, reg, reg)
proc = io.popen(cmd)

while true do
  line = proc:read()
  if line then
    if line:find('responded to query from') then
      ip = line:match('%d+%.%d+%.%d+%.%d+')
      log('NTP query', ip)
    end
  else
    break
  end
end

proc:close()



RE: NTP Client Details - CHOUAIBOU - 30.09.2025

(30.09.2025, 08:22)admin Wrote: Disable both NTP server and client in system config. Create a resident script with sleep time set to 5 seconds. You can replace region (europe) with 2-letter country code (de, fr, etc) for more precise time updates.
Code:
reg = 'europe'
cmd = '/usr/sbin/ntpd -ddd -l -n -p 0.%s.pool.ntp.org -p 1.%s.pool.ntp.org -p 2.%s.pool.ntp.org -p 3.%s.pool.ntp.org 2>&1'
cmd = string.format(cmd, reg, reg, reg, reg)
proc = io.popen(cmd)

while true do
  line = proc:read()
  if line then
    if line:find('responded to query from') then
      ip = line:match('%d+%.%d+%.%d+%.%d+')
      log('NTP query', ip)
    end
  else
    break
  end
end

proc:close()
Hi admin,
Many thanks!
I will test the script and give feedback

(30.09.2025, 09:11)CHOUAIBOU Wrote:
(30.09.2025, 08:22)admin Wrote: Disable both NTP server and client in system config. Create a resident script with sleep time set to 5 seconds. You can replace region (europe) with 2-letter country code (de, fr, etc) for more precise time updates.
Code:
reg = 'europe'
cmd = '/usr/sbin/ntpd -ddd -l -n -p 0.%s.pool.ntp.org -p 1.%s.pool.ntp.org -p 2.%s.pool.ntp.org -p 3.%s.pool.ntp.org 2>&1'
cmd = string.format(cmd, reg, reg, reg, reg)
proc = io.popen(cmd)

while true do
  line = proc:read()
  if line then
    if line:find('responded to query from') then
      ip = line:match('%d+%.%d+%.%d+%.%d+')
      log('NTP query', ip)
    end
  else
    break
  end
end

proc:close()
Hi admin,
Many thanks!
I will test the script and give feedback

Hi admin,
The script is working fine. The LM is not actually connected to the internet.
I am using my Laptop NTP server.

Thanks!

Below the logs:

LM_As_NTP_Server_Debugger 30.09.2025 12:00:35
* string: ntpd: sending query to 10.195.221.101

LM_As_NTP_Server_Debugger 30.09.2025 12:00:35
* string: ntpd: reply from 10.195.221.101: offset:+0.000217 delay:0.002551 status:0x24 strat:1 refid:0x4c434f4c rootdelay:0.000000 reach:0x7f

LM_As_NTP_Server_Debugger 30.09.2025 12:00:35
* string: ntpd: update from:10.195.221.101 offset:+0.000217 delay:0.002551 jitter:0.002000 clock drift:+0.329ppm tc:5

LM_As_NTP_Server_Debugger 30.09.2025 12:00:35
* string: ntpd: poll:32s sockets:1 interval:32s

LM


RE: NTP Client Details - CHOUAIBOU - 01.10.2025

(30.09.2025, 08:22)admin Wrote: Disable both NTP server and client in system config. Create a resident script with sleep time set to 5 seconds. You can replace region (europe) with 2-letter country code (de, fr, etc) for more precise time updates.
Code:
reg = 'europe'
cmd = '/usr/sbin/ntpd -ddd -l -n -p 0.%s.pool.ntp.org -p 1.%s.pool.ntp.org -p 2.%s.pool.ntp.org -p 3.%s.pool.ntp.org 2>&1'
cmd = string.format(cmd, reg, reg, reg, reg)
proc = io.popen(cmd)

while true do
  line = proc:read()
  if line then
    if line:find('responded to query from') then
      ip = line:match('%d+%.%d+%.%d+%.%d+')
      log('NTP query', ip)
    end
  else
    break
  end
end

proc:close()

Hi admin,
Please do we have any compatibilty matrix file of SNTP and NTP versions (Client /Server)?
It seams like it is important for the Client / Server to work properly.

Thanks!


RE: NTP Client Details - admin - 01.10.2025

LM NTP client/server operates at version 4 by default. But replying to clients with older versions is also possible. What NTP clients are you using?

If you want precise time you should allow LM to synchronize with a real NTP server. Internal LM clock is not guaranteed to be accurate enough for long time periods.


RE: NTP Client Details - CHOUAIBOU - 01.10.2025

(01.10.2025, 08:48)admin Wrote: LM NTP client/server operates at version 4 by default. But replying to clients with older versions is also possible. What NTP clients are you using?

If you want precise time you should allow LM to synchronize with a real NTP server. Internal LM clock is not guaranteed to be accurate enough for long time periods.

Hi admin,
Thank you for your reply.
I am using NTP Cient version 4.
Can LM NTP client synchronizes with a server with an SNTP protocol? Or is it mandatory for both to support same Network Time Protocol NTP or SNTP?

Thanks!


RE: NTP Client Details - admin - 01.10.2025

It should work with SNTP too. Use this script to check the connection: https://forum.logicmachine.net/showthread.php?tid=4823&pid=31293#pid31293


RE: NTP Client Details - CHOUAIBOU - 02.10.2025

(01.10.2025, 12:14)admin Wrote: It should work with SNTP too. Use this script to check the connection: https://forum.logicmachine.net/showthread.php?tid=4823&pid=31293#pid31293

Thank you admin or sharing the link.
I will use it to check the connection.