Basically, I have a couple Windows computers on my network that will be running a python script. A different set of configuration options should be used in the script depending on which computer is running this script.
How would I get that computer name in the python script?
Let's say the script was running on a computer named DARK-TOWER, I'd like to write something like this:
>>> python.library.get_computer_name()
'DARK-TOWER'
Is there a standard or third party library I can use?
From https://mail.python.org/pipermail/python-list/2006-April/397494.html
It turns out there are three options (including the two already answered earlier):
As Eric Carr said you could use these three variants.
I prefer using them together:
I prefer it when developing cross patform applications to be sure ;)
Since the python scrips are for sure running on a windows system, you should use the Win32 API GetComputerName or GetComputerNameEx
You can get the fully qualified DNS name, or NETBIOS name, or a variety of different things.
Or:
I bet gethostname will work beautifully.