Help?? Struct packing of Date time not has stopped working??!?!

Klaus Baldermann kbaldermann at entire-systems.com
Thu Dec 16 07:10:05 EST 1999


Benjamin Schollnick wrote in message ...

>Both !L, & !d (Long, and Double), were not unpacking
>correctly.


no wonder, when the buffer passed to it doesn't match the format.

>Is there someway to have telnetlib return BINARY data directly?

Now THIS is the key. After a bit more checking the time server's output
as returned by telnetlib I found out that several characters are not
passed through (Nulls, Control-Q, etc). After a look at telnetlib.py
it became obvious that telnetlib is too sophisticated for our purpose.
A simple socket should do, see below


--- snip ---
# set the time from server
import socket, struct, time, os, sys
corr =  2208988800L # Differenz zwischen 1.1.1900 (vom Server) und 1.1.1970
(localtime)

if len(sys.argv) < 2:
    host = 'www.alz.mgi.de'
else:
    host = sys.argv[1]

connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect((host, 37))
line = connection.recv(4)
connection.close()

seconds = struct.unpack('!L',line)[0] - corr
timestring = time.strftime("%X", time.localtime(seconds))
os.system("time " + timestring) # this is for MS-DOG, Losedows, etc.
print "time set to", timestring
--- snip ---

HTH
Klaus








More information about the Python-list mailing list