How to get hostname in Python on Linux?

In Python, how to get hostname as the command hostname does on Linux?

asked Mar 17 by anonymous

1 Answer

In Python, you can get the hostname by the socket.gethostname() library function in the socket module:

import socket

hostname = socket.gethostname()

Reference: https://www.systutorials.com/dtivl/20/how-to-get-the-hostname-of-the-node?show=34#a34

answered Apr 20 by zma (380 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...