I'm writing a chat program for a local network. I would like to be able to identify computers and get the user-set computer name with Python.
The best way to get hostname of the computer is by using socket and its gethostname() functionality.
The Socket module provides access to the socket interface. It is available on all modern Unix systems, Windows, MacOS, and probably additional platforms.
The gethostname() function returns a socket object whose methods implement the various socket system calls. Parameter types are somewhat higher-level than in the C interface: as with read()and write() operations on Python files, buffer allocation on receive operations is automatic, and buffer length is implicit on send operations.
This function returns a string containing the hostname of the machine where the Python interpreter is currently executing.
import socket print(socket.gethostname())
Another thing you can do is use a platform module.
Certification in Digital Marketing |
Certification in Big Data Analytics |
Certification in Cloud & Devops |
Certification in Full Stack Web Development
Big Data and Data Science Master’s Course |
Data Science Architect Master’s Program |
Cloud and DevOps Architect Master’s Course |
Artificial Intelligence Engineer Master’s Course |
Microsoft Azure Certification Master’s Training
Data Science Course Online |
Big Data Hadoop Certification Training |
Machine Learning Course Online |
Artificial Intelligence Course and Training |
Salesforce Certification Training: Administrator and App Builder |
Tableau Training and Certification Course |
Python Data Science Course & Training |
Ethical Hacking Course |
Business Analyst Course |
Courses in Cyber Security
© COPYRIGHT 2011-2021 INTELLIPAAT.COM. ALL RIGHTS RESERVED.