Skip to content

How to get the Hostname in Python

If you need to get the Hostname in your Python application, then you can do the following:

Option 1 – Using gethostname()

import socket print(socket.gethostname())
Code language: Python (python)

Option 2 – Using the platform module

import platform print (platform.node())
Code language: Python (python)

Option 3 – Using os.uname()

import os hname = os.uname() print(hname)
Code language: Python (python)

See also  Number of Rectangles in a Grid in Java
Tags:
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Software House
26 days ago

Thanks for guidance, now it’s very easy for me to create user platform using pyhton

1
0
Would love your thoughts, please comment.x
()
x