inet_aton and struct issue

David Bear david.bear at asu.edu
Wed Aug 30 17:11:38 EDT 2006


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?

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --



More information about the Python-list mailing list