Querying Information About Servers
Server information is provided by the
PySERVER_INFO_* structures, as defined in Appendix B. PySERVER_INFO_100 provides
the lowest level of detail, so let’s see what this includes.
First import the necessary modules and read the data for the server. Then print the dictionary:
>>> import win32net, win32netcon
>>> data=win32net.NetServerGetInfo(None, 100)
>>> data
{'name': L'BOBCAT', 'platform_id': 500}Notice the platform_id is 500. Windows defines
only two platform IDs, one for Windows NT and one for OS/2:
>>> win32netcon.SV_PLATFORM_ID_NT 500 >>>
My workstation is indeed an NT machine: what a relief!
You can also obtain a list of the Windows servers on your network
with the
win32net.NetServerEnum()
function.
entries, total, resume = win32net.NetServerEnum(server,level, serverTypes= win32netcon.SV_TYPE_ALL, resume = 0, len=4096)
-
server The name of the server to execute on or
Nonefor the current machine.-
level An integer specifying the level of information requested.
-
serverTypes A bitmask of flags indicating the types of servers to list. Appendix B lists common values for this flag.
We don’t discuss the resume or
len parameters, or the result. Check the previous
example for win32net.NetUserEnum() to see how to
use these enumerators.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access