On this page
socket.gethostbyname
Prev: socket.gethostbyaddr | Up: socket | Next: socket.gethostbyname_ex
Rel: socket.AddressFamily, socket.close, socket.create_connection, socket.create_server
Ref: docs.python.org — socket.gethostbyname
Tags: #public #python3 #stdlib #socket
Import
import socket
from socket import gethostbyname
Signature & Overview
socket.gethostbyname(host) -> address
Return the IP address (a string of the form '255.255.255.255') for a host.
Usage
import socket
ip = socket.gethostbyname("localhost")
assert ip.startswith("127.")
Gotchas
- IPv4-only legacy API: Use
socket.getaddrinfo()to support both IPv4 and IPv6.
REPL Inspect
from socket import gethostbyname
help(gethostbyname)
Linked from
Related notes
- tuts/python3/stdlib_module/socket/gethostbyaddr Linked here; links to this page; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/gethostbyname_ex Linked here; links to this page; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/AddressFamily Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/close Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/create_connection Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/create_server Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/socket Linked here; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/socket/dup shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/error shared tags: #socket, #stdlib