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.
Locating Your Computer's Hostname on a PC (Windows 10)In the window the window that appears on the bottom-left hand corner of your screen, type in cmd and click OK. The command prompt window will appear. In this window, type hostname and press Enter. The name of your computer will be displayed.
The hostname is what a device is called on a network. Alternative terms for this are computer name and site name. The hostname is used to distinguish devices within a local network. In addition, computers can be found by others through the hostname, which enables data exchange within a network, for example.
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With