On this page
  1. socket.inet_pton
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

socket.inet_pton

Prev: socket.inet_ntop | Up: socket | Next: socket.ntohl
Rel: socket.AddressFamily, socket.close, socket.create_connection, socket.create_server
Ref: docs.python.org — socket.inet_pton
Tags: #public #python3 #stdlib #socket


Import

import socket
from socket import inet_pton

Signature & Overview

socket.inet_pton(af, ip) -> packed IP address string

Convert an IP address from string format to a packed string suitable for use with low-level network functions.

Usage

import socket

assert socket.inet_pton(socket.AF_INET, "10.0.0.1") == b"\x0a\x00\x00\x01"
assert socket.inet_pton(socket.AF_INET6, "::1") == b"\x00" * 15 + b"\x01"

Gotchas

REPL Inspect

from socket import inet_pton
help(inet_pton)

Linked from

Related notes