Machine identification

G

Greg Lindstrom

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 (e-mail address removed)

"We are the music makers, and we are the dreamers of dreams" W.W.
 
B

Brad Tilley

Greg said:
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 (e-mail address removed)

"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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Sharing Base Class members 0
Oracle Access via cx_Oracle 1
Pattern Matching 0
Oracle Access via cx_Oracle 0
Boa Constructor Problem 5
mySQL access 2
pyDAV 0
Oracle Access via cx_Oracle 1

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top