summaryrefslogtreecommitdiff
path: root/source4/scripting/bin/smbstatus
blob: 782e83e4cf68a6c449cefd5f6a3098ed372f57bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#  provide information on connected users and open files
#  Copyright ǒ Jelmer Vernooij 2008
#
#  Based on the original in EJS:
#  Copyright Andrew Tridgell 2005
#  Released under the GNU GPL version 3 or later
#

import sys

sys.path.insert(0, "bin/python")

import optparse
import samba.getopt as options
import samba.irpc

def show_sessions():
	"""show open sessions"""
	sessions = smbsrv_sessions()
	print "User                                  Client      Connected at"
	print "-------------------------------------------------------------------------------"
	for session in sessions:
		fulluser = "%s/%s" % (session.account_name, session.domain_name)
		print "%-30s %16s   %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time))
	print ""

def show_tcons():
	"""show open tree connects"""
	tcons = smbsrv_tcons()
	print "Share                                 Client      Connected at"
	print "-------------------------------------------------------------------------------"
	for tcon in tcons:
		print "%-30s %16s   %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time))


def show_nbt():
	"""show nbtd information"""
	stats = nbtd_statistics()
	print "NBT server statistics:",
	for r in stats:
		print "\t" + r + ":\t" + stats[r] + "\n"
	print ""

parser = optparse.OptionParser("%s [options]" % sys.argv[0])
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option("--nbt", type="string", metavar="NBT", 
        help="show NetBIOS status")

lp = sambaopts.get_loadparm()

print "%s\n\n" % lp.get("server string")

if opts.nbt:
	show_nbt()
else:
	show_sessions()
	show_tcons()

return 0