On this page
socket.gethostname
Prev: socket.gethostbyname_ex | Up: socket | Next: socket.getnameinfo
Rel: socket.AddressFamily, socket.close, socket.create_connection, socket.create_server
Ref: docs.python.org — socket.gethostname
Tags: #public #python3 #stdlib #socket
Import
import socket
from socket import gethostname
Signature & Overview
socket.gethostname()
Return the current host name.
Usage
import socket
name = socket.gethostname()
assert isinstance(name, str) and len(name) > 0
Gotchas
- Returns the local machine's hostname: Doesn't guarantee it resolves in DNS.
REPL Inspect
from socket import gethostname
help(gethostname)
Linked from
Related notes
- tuts/python3/stdlib_module/socket/gethostbyname_ex Linked here; links to this page; shared tags: #socket, #stdlib
- tuts/python3/stdlib_module/socket/getnameinfo 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