What’s the best way to find the hostname in python?

Posted in python

Fifty million ways to get the hostname, choose one.

import os,socket,platform,re
print socket.gethostname()
print platform.uname()[1]
print platform.node()

But I couldn’t find a way to get the shortname without a system call to ‘hostname -s’. This is the best I could come up with, which would work with any of the above methods.

import os,re
print re.sub(r'\..*', '', os.uname()[1])
Posted by admica   @   7 October 2009
Tags : , , , ,

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Why is it so hard to get Internet service without cable and phone?
Next Post
Geany is the best code editor »
Powered by Wordpress   |   Lunated designed by ZenVerse