使用函数 : socket.gethostname()

示例代码:

import socket

print(socket.gethostname())

更多推荐

Python 网络编程 : Socket 获取本地主机名 socket.gethostname() 函数 -YDOOK