Machine identification

Discussion in 'Python' started by Greg Lindstrom, Sep 8, 2004.

  1. How can I get the name (or ip) of the machine where my python script is
    running? I'd like to add it to my log entry.

    Thanks,

    --greg

    Greg Lindstrom (501) 975-4859
    NovaSys Health

    "We are the music makers, and we are the dreamers of dreams" W.W.
     
    Greg Lindstrom, Sep 8, 2004
    #1
    1. Advertising

  2. Greg Lindstrom

    Brad Tilley Guest

    Greg Lindstrom wrote:
    > How can I get the name (or ip) of the machine where my python script is
    > running? I'd like to add it to my log entry.
    >
    > Thanks,
    >
    > --greg
    >
    > Greg Lindstrom (501) 975-4859
    > NovaSys Health
    >
    > "We are the music makers, and we are the dreamers of dreams" W.W.


    You might also consider getting this info from the Windows registry if
    you're running a Windows PC:

    This code:

    #-------------------------------------------------
    from _winreg import *

    def list_run_at_boot():
    run_key =
    r"SYSTEM\ControlSet001\Services\{A9A76D2B-8D75-413F-A2F1-013095F2B61C}\Parameters\Tcpip"
    open_run_key = OpenKey(HKEY_LOCAL_MACHINE, run_key, 0, KEY_READ)
    print "Name \t Value\n"
    for i in range (10000):
    try:
    n,v,t = EnumValue(open_run_key, i)
    print n, "\t", v
    except EnvironmentError:
    print "\nThere are", i, "values under this key."
    break
    CloseKey(open_run_key)

    list_run_at_boot()

    #---------------------------------------------------

    Produces this output:

    #---------------------------------------------------

    Name Value

    EnableDHCP 1
    IPAddress [u'0.0.0.0']
    SubnetMask [u'0.0.0.0']
    DefaultGateway []
    DhcpIPAddress 192.168.1.100
    DhcpSubnetMask 255.255.255.0
    DhcpServer 192.168.1.1
    Lease 86400
    LeaseObtainedTime 1094701976
    T1 1094745176
    T2 1094777576
    LeaseTerminatesTime 1094788376
    DhcpDefaultGateway [u'192.168.1.1']
    DhcpSubnetMaskOpt [u'255.255.255.0']

    There are 14 values under this key.

    #---------------------------------------------------

    Best of luck,
    Brad
     
    Brad Tilley, Sep 9, 2004
    #2
    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. Sorin Sandu

    Client identification

    Sorin Sandu, Apr 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    386
    Guest
    Apr 9, 2004
  2. Sorin Sandu

    Re: Client identification

    Sorin Sandu, Apr 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    345
    Bruno Sirianni
    Apr 9, 2004
  3. Daniel Jorge
    Replies:
    5
    Views:
    603
  4. guy

    identification of NET objects

    guy, Sep 6, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    358
    Eliyahu Goldin
    Sep 6, 2005
  5. Skip Montanaro

    Re: Machine identification

    Skip Montanaro, Sep 8, 2004, in forum: Python
    Replies:
    5
    Views:
    393
    Jeff Epler
    Sep 9, 2004
Loading...

Share This Page