python inet_ntoa function

The inet_ntoa function of python socket module converts an ip address of 32 bit packed format to dotted-quad string format.

socket Updated 31 Jan 2017 1 min read

Function Name

inet_ntoa(ip_address)

Parameters

ip_address – The address in 32-bit packed format which is to be converted

Return Value

Returns the IP address in dotted quad-string format.

Function Overview

Converts an IP address, which is in 32-bit packed format to the popular human readable dotted-quad string format.

Example

python
import socket

import struct

IPLong  = 168496141

IP32Bit = struct.pack('!I', IPLong)

IPQuad  = socket.inet_ntoa(IP32Bit)

print(IPQuad)

The Python example above first converts an IP address in decimal format to 32 bit packed address.

Using the function inet_ntoa it converts the 32 bit packed address into the dotted-quad string format.

Output

Output
10.11.12.13