socket.gethostname()
socket.gethostname() is a Python function in the Socket Module category. Returns the hostname of the local machine. The syntax is socket.gethostname(). Returns: String. A typical example: socket.gethostname() # "my-pc". A close sibling is socket.socket(), which creates a socket for network communication. Default creates a TCP/IP socket. A close sibling is socket.bind(), which binds the socket to a local address (host, port) for receiving connections. A close sibling is socket.listen(), which enables the socket to accept connection requests (server mode). A close sibling is socket.accept(), which accepts a connection. Returns (client_socket, client_address) tuple. More about this category: Network communication — socket, connect, bind, listen, accept, send, recv. Related Socket Module entries: socket.socket(), socket.bind(), socket.listen(), socket.accept(), socket.connect(), socket.send(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try socket.gethostname() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.