Content
How can I use Python to get the system hostname? Asked 9 years, 8 months ago Active 1 year, 4 months ago Viewed 525k times 698 I’m writing a chat program for a local network. I would like be able to identify computers and get the user-set computer name with Python. python hostname share edit follow flag 98 edited Sep 13 ’16 at 16:00 Itay Grudev 5,455 4 39 76 asked Nov 24 ’10 at 21:33 John 12.9k 10 40 63 add a comment start a bounty 11 Answers Active Oldest Votes 1064 Use socket and its gethostname () functionality. This will get the hostname of the computer where the Python interpreter is running: import socket print (socket. gethostname ()) V f9 share edit follow flag edited Feb 10 ’15 at 23:02 the Tin Man 146k 30 192 272 answered Nov 24 ’10 at 21:36 Alex 55.8k 45 143 174 70 well, that’s not correct. It works for me offline and in home, but now I am a office and this returns a different host name. – DataGreed Jun 21 ’12 at 13:39