How to get computer name

Discussion in 'Python' started by pitarda, Apr 29, 2006.

  1. pitarda

    pitarda Guest

    How do I get the computer name in python?

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

    Thanks!

    Bud
     
    pitarda, Apr 29, 2006
    #1
    1. Advertising

  2. pitarda

    Tim Heaney Guest

    "pitarda" <> writes:

    > How do I get the computer name in python?


    You can use the os module to get it from your environment.

    >>> import os
    >>> os.getenv('HOSTNAME')

    'calvin.watterson'

    Depending on your operating system, the environment variable you need
    might have a different name. For example, I think in Windows you
    might try

    >>> os.getenv('COMPUTERNAME')


    You can see all of the environment variables currently available with

    >>> os.environ


    I hope this helps,

    Tim
     
    Tim Heaney, Apr 29, 2006
    #2
    1. Advertising

  3. pitarda

    pitarda Guest

    Thanks! :)

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

    :)
     
    pitarda, Apr 29, 2006
    #3
  4. On 29 Apr 2006 10:04:39 -0700, pitarda wrote:

    > Thanks! :)
    >
    > Though,... I think once I saw something like: getComputerByName but
    > can't find it anymore,...
    >
    > :)


    >>> import socket
    >>> print socket.gethostname()

    blade
    >>> print socket.gethostbyname('blade') # will print IP address



    --
    Richard
     
    Richard Townsend, Apr 29, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bk
    Replies:
    0
    Views:
    482
  2. draganc

    get computer name in LAN

    draganc, Nov 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    710
    draganc
    Nov 29, 2003
  3. =?Utf-8?B?RGFuIE5hc2g=?=

    get computer name

    =?Utf-8?B?RGFuIE5hc2g=?=, Oct 11, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    6,228
    William F. Robertson, Jr.
    Oct 11, 2004
  4. Johnson
    Replies:
    1
    Views:
    332
    Marina
    Feb 22, 2005
  5. ding feng
    Replies:
    2
    Views:
    2,881
    ding feng
    Jun 25, 2003
Loading...

Share This Page