How to get hostname in Python on Linux?

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

asked Mar 17, 2017 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()


answered Apr 20, 2017 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