[Tutor] Renaming computers

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Thu Mar 23 23:18:27 CET 2006


Danny Yoo wrote:
> There are examples of programs that people have written to 
> automate some Windows administration tasks.  For example:
> 
>     http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347812
> 
> is code to get the MAC address of one's ethernet card

You can also use WMI for this task.  The pywin32 package is required.
Here is an example using the interactive interpreter:

>>> from win32com.client import GetObject
>>> machine = GetObject('winmgmts://some_remote_machine/root/cimv2')
>>> query = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE
IPEnabled = True"
>>> adapters = machine.ExecQuery(query)
>>> macs = [a.MACAddress for a in adapters]
>>> for m in macs: print m
... 
00:0E:0C:82:7A:33
00:14:22:0F:54:3C

Christian
http://www.dowski.com


More information about the Tutor mailing list