The best way to get the Hostname in Python
If it is advisable get the Hostname in your Python software, then you are able to do the next:
Choice 1 – Utilizing gethostname()
#
import socket
print(socket.gethostname())
Choice 2 – Utilizing the platform
module#
import platform
print (platform.node())
Choice 3 – Utilizing os.uname()
#
import os
hname = os.uname()
print(hname)