Python Inet_aton Function

Function Name:

inet_aton(ip_address)

 

Parameter(s):

The ip_address, which needs to be converted from the dotted-quad, string format to 32 bit packed binary format.

 

Function Overview:

As per IPv4, an IP Address is a 32-bit number. These IPv4 addresses are represented as four decimal numbers. Each number is separated by a dot and each number ranges from 0 to 255. The function inet_aton() converts an IPv4 address from the dotted-quad string format to 32-bit packed binary format. The binary format returned could be passed to any program that requires IP address as an object of C type struct in_addr.

 

Example:

 

import socket

import struct

 

IPQuad      = "192.168.0.0"

IP32Bit     = socket.inet_aton(IPQuad) 

print(IP32Bit)

 

Output:

b'\xc0\xa8\x00\x00

 


Copyright 2018 © pythontic.com