Загрузка данных


python3 - <<'PY'
import socket
for ip in ['169.254.169.123', '10.3.3.24']:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.settimeout(3)
    try:
        s.sendto(b'\x23' + bytes(47), (ip, 123))
        r, _ = s.recvfrom(512)
        ok = len(r) >= 48 and r[0] & 7 == 4 and 1 <= r[1] <= 15 and r[0] >> 6 != 3
        print(ip, 'NTP OK' if ok else 'INVALID NTP')
    except socket.timeout:
        print(ip, 'TIMEOUT')
    finally:
        s.close()
PY