如何使用Python获取系统主机名? [英] How can I use Python to get the system hostname?
本文介绍了如何使用Python获取系统主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为本地网络编写聊天程序.我希望能够识别计算机并使用Python获取用户设置的计算机名称.
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.
推荐答案
使用 socket
及其 gethostname()
功能.这将获得运行Python解释器的计算机的hostname
:
import socket
print(socket.gethostname())
这篇关于如何使用Python获取系统主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文