[Tutor] Python -> uname -n
Tim Johnson
tim at johnsons-web.com
Tue Sep 14 01:34:44 CEST 2004
* Danny Yoo <dyoo at hkn.eecs.berkeley.edu> [040913 14:35]:
>
>
> On Mon, 13 Sep 2004, Tim Johnson wrote:
>
> > > How may I obtain the network node hostname with python?
> > >
> > > On linux, it would be the value returned by 'uname -n'
> >
> > Found it all by my lonesome, under Python Library Reference, the
> > 'commands' module.
> >
> > commands.getstatusoutput('uname -n') returns a 2 - member tuple with
> > status code as the first item and response string as second item.
>
>
> Hi Tim,
>
>
> You might be able to get it with 'socket.gethostname()' as well:
The commands module will prove to be very helpful in other issues
for me, but I see that the socket module is more portable and
won't make python barf in Windows, so it looks like the
'socket' aproach is preferable.
Thanks Danny
tim
> ###
> >>> import socket
> >>> socket.gethostname()
> 'shoebox'
> ###
>
>
> See:
>
> http://www.python.org/doc/lib/module-socket.html#l2h-2417
>
> for more details on socket.gethostname().
>
>
> Good luck!
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list