source: branches/samba-3.5.x/source3/stf/osver.py@ 1075

Last change on this file since 1075 was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 1.5 KB
Line 
1#!/usr/bin/python
2#
3# Utilities for determining the Windows operating system version remotely.
4#
5
6from samba import srvsvc
7
8# Constants
9
10PLATFORM_UNKNOWN = 0
11PLATFORM_WIN9X = 1
12PLATFORM_NT4 = 2
13PLATFORM_NT5 = 3 # Windows 2000
14
15def platform_name(platform_type):
16
17 platform_names = { PLATFORM_UNKNOWN: "Unknown",
18 PLATFORM_WIN9X: "Windows 9x",
19 PLATFORM_NT4: "Windows NT",
20 PLATFORM_NT5: "Windows 2000" }
21
22 if platform_names.has_key(platform_type):
23 return platform_names[platform_type]
24
25 return "Unknown"
26
27def platform_type(info101):
28 """Determine the operating system type from a SRV_INFO_101."""
29
30 if info101['major_version'] == 4 and info101['minor_version'] == 0:
31 return PLATFORM_NT4
32
33 if info101['major_version'] == 5 and info101['minor_version'] == 0:
34 return PLATFORM_NT5
35
36 return PLATFORM_UNKNOWN
37
38def is_domain_controller(info101):
39 """Return true if the server_type field from a SRV_INFO_101
40 indicates a domain controller."""
41 return info101['server_type'] & srvsvc.SV_TYPE_DOMAIN_CTRL
42
43def os_version(name):
44 info = srvsvc.netservergetinfo("\\\\%s" % name, 101)
45 return platform_type(info)
46
47if __name__ == "__main__":
48 import sys
49 if len(sys.argv) != 2:
50 print "Usage: osver.py server"
51 sys.exit(0)
52 info = srvsvc.netservergetinfo("\\\\%s" % sys.argv[1], 101)
53 print "platform type = %d" % platform_type(info)
54 if is_domain_controller(info):
55 print "%s is a domain controller" % sys.argv[1]
Note: See TracBrowser for help on using the repository browser.