Bootstrap FreeKB - Python (Scripting) - hostname (socket)
Python (Scripting) - hostname (socket)

Updated:   |  Python (Scripting) articles

socket can be used to get the system hostname in a Python script. In this example, the full system hostname will be printed.

#!/bin/python
import socket
print(socket.gethostname())

 

In this example, only the first field of the hostname will be printed (short).

#!/bin/python
import socket
print(socket.gethostname().split('.', 1)[0])

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2f03de in the box below so that we can be sure you are a human.