snippetpythonCriticalCanonical
How can I use Python to get the system hostname?
Viewed 0 times
howusethehostnamecanpythonsystemget
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.