HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonCritical

How can I use Python to get the system hostname?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howsystemgetpythonthecanusehostname

Problem

I'm writing a chat program for a local network. I would like be able to identify computers and get the user-set computer name with Python.

Solution

Use socket and its gethostname() functionality. This will get the hostname of the computer where the Python interpreter is running:

import socket
print(socket.gethostname())

Code Snippets

import socket
print(socket.gethostname())

Context

Stack Overflow Q#4271740, score: 1506

Revisions (0)

No revisions yet.