How to get computer name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pitarda

    How to get computer name

    How do I get the computer name in python?

    I've been looking over the internet, and couldn't find anything.

    Thanks!

    Bud

  • Tim Heaney

    #2
    Re: How to get computer name

    "pitarda" <pitarda@gmail. com> writes:
    [color=blue]
    > How do I get the computer name in python?[/color]

    You can use the os module to get it from your environment.
    [color=blue][color=green][color=darkred]
    >>> import os
    >>> os.getenv('HOST NAME')[/color][/color][/color]
    'calvin.watters on'

    Depending on your operating system, the environment variable you need
    might have a different name. For example, I think in Windows you
    might try
    [color=blue][color=green][color=darkred]
    >>> os.getenv('COMP UTERNAME')[/color][/color][/color]

    You can see all of the environment variables currently available with
    [color=blue][color=green][color=darkred]
    >>> os.environ[/color][/color][/color]

    I hope this helps,

    Tim

    Comment

    • pitarda

      #3
      Re: How to get computer name

      Thanks! :)

      Though,... I think once I saw something like: getComputerByNa me but
      can't find it anymore,...

      :)

      Comment

      • Richard Townsend

        #4
        Re: How to get computer name

        On 29 Apr 2006 10:04:39 -0700, pitarda wrote:
        [color=blue]
        > Thanks! :)
        >
        > Though,... I think once I saw something like: getComputerByNa me but
        > can't find it anymore,...
        >
        > :)[/color]
        [color=blue][color=green][color=darkred]
        >>> import socket
        >>> print socket.gethostn ame()[/color][/color][/color]
        blade[color=blue][color=green][color=darkred]
        >>> print socket.gethostb yname('blade') # will print IP address[/color][/color][/color]


        --
        Richard

        Comment

        Working...