Faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 9 people (44%) answered Yes
Recently 1 of 6 people (17%) answered Yes

Entry

How do I take an int, which represents an IP address, and convert it back to dotted quad format? (in C, it's inet_ntoa)

Aug 2nd, 2000 06:58
Jon Nelson, unknown unknown, deja (can't remember *who*, though)


def ntoa(long):
  return 
string.join(map(str,struct.unpack('4B',struct.pack('<L',long))),'.')

In Python 1.6a2 (2.0) it's in the socket module, as inet_ntoa afaik.