Diez B. Roggisch wrote: > David Bear schrieb: >> I found this simple recipe for converting a dotted quad ip address to a >> string of a long int. >> >> struct.unpack('L',socket.inet_aton(ip))[0] >> >> trouble is when I use this, I get >> >> struct.error: unpack str size does not match format >> >> I thought ip addresses were unsigned 32 bit integers. >> >> Is there a better way to take a dotted quad and convert it to a string >> representation of an long int? > > Works for me: > > >>> import socket > >>> import struct > >>> ip = "127.0.0.1" > >>> struct.unpack('L',socket.inet_aton(ip))[0] > 2130706433L >
I really wish it worked for me: >>> struct.unpack('L', socket.inet_aton('129.219.120.129')) Traceback (most recent call last): File "<stdin>", line 1, in ? struct.error: unpack str size does not match format This is python packaged with Suse 9.3. >>> dir(struct) ['__doc__', '__file__', '__name__', 'calcsize', 'error', 'pack', 'unpack'] >>> print struct.__file__ /usr/lib64/python2.4/lib-dynload/struct.so could I have a broken python? > > Diez -- David Bear -- let me buy your intellectual property, I want to own your thoughts -- -- http://mail.python.org/mailman/listinfo/python-list