This should allow you to check if you can access an external NTP server on port 123. Works for Python 2 or 3 ...
Code:
import socketGET_NTP_TIME_URL = "pool.ntp.org"GET_NTP_TIME_PORT = 123print("Try accessing {}:{}".format(GET_NTP_TIME_URL, GET_NTP_TIME_PORT))packet = bytearray(48)packet[0] = 0x1Bserver = socket.getaddrinfo(GET_NTP_TIME_URL, GET_NTP_TIME_PORT)[0][-1]skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)skt.settimeout(1)skt.sendto(packet, server)reply = skt.recv(1024)skt.close()print("Success")
Code:
pi@Pi3B:~/apps/ntp $ python2 check_ntp_access.pyTry accessing pool.ntp.org:123Success
Statistics: Posted by hippy — Fri Apr 12, 2024 5:18 pm