2010-03-24 08:50:50 +03:00
#!/usr/bin/env python
2008-05-26 04:04:00 +04:00
# -*- 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
#
2008-05-26 07:00:45 +04:00
import os, sys
2008-05-26 04:04:00 +04:00
sys.path.insert(0, "bin/python")
import optparse
import samba.getopt as options
2008-05-26 07:00:45 +04:00
from samba import irpc, messaging
2008-05-26 04:04:00 +04:00
2008-05-26 06:14:28 +04:00
def show_sessions(conn):
2008-05-26 04:04:00 +04:00
"""show open sessions"""
2008-05-26 07:12:31 +04:00
2008-05-26 06:14:28 +04:00
sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next()
2008-05-26 04:04:00 +04:00
print "User Client Connected at"
2008-09-18 23:32:30 +04:00
print "-" * 79
2008-05-26 04:04:00 +04:00
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 ""
2008-05-26 06:14:28 +04:00
def show_tcons(open_connection):
2008-05-26 04:04:00 +04:00
"""show open tree connects"""
2008-05-26 06:14:28 +04:00
conn = open_connection("smb_server")
tcons = conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS).next()
2008-05-26 04:04:00 +04:00
print "Share Client Connected at"
2008-09-18 23:32:30 +04:00
print "-" * 79
2008-05-26 04:04:00 +04:00
for tcon in tcons:
2008-05-26 07:00:45 +04:00
print "%-30s %16s %s" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time))
2008-05-26 04:04:00 +04:00
2008-05-26 06:14:28 +04:00
def show_nbt(open_connection):
2008-05-26 04:04:00 +04:00
"""show nbtd information"""
2008-05-26 06:14:28 +04:00
conn = open_connection("nbt_server")
stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next()
print "NBT server statistics:"
2008-05-26 07:00:45 +04:00
fields = [("total_received", "Total received"),
("total_sent", "Total sent"),
("query_count", "Query count"),
("register_count", "Register count"),
("release_count", "Release count")]
for (field, description) in fields:
print "\t%s:\t%s" % (description, getattr(stats, field))
print
2008-05-26 04:04:00 +04:00
parser = optparse.OptionParser("%s [options]" % sys.argv[0])
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
2008-05-26 06:14:28 +04:00
parser.add_option("--messaging-path", type="string", metavar="PATH",
help="messaging path")
parser.add_option("--nbt", help="show NetBIOS status", action="store_true")
opts, args = parser.parse_args()
2008-05-26 04:04:00 +04:00
lp = sambaopts.get_loadparm()
2008-05-26 07:00:45 +04:00
print "%s" % lp.get("server string")
messaging_path = (opts.messaging_path or os.path.join(lp.get("private dir"), "smbd.tmp", "messaging"))
2008-05-26 04:04:00 +04:00
2008-05-26 06:14:28 +04:00
def open_connection(name):
2008-05-26 07:00:45 +04:00
return messaging.ClientConnection(name, messaging_path=messaging_path)
2008-05-26 06:14:28 +04:00
2008-05-26 04:04:00 +04:00
if opts.nbt:
2008-05-26 06:14:28 +04:00
show_nbt(open_connection)
2008-05-26 04:04:00 +04:00
else:
2008-05-26 07:12:31 +04:00
try:
conn = open_connection("smb_server")
except RuntimeError, (num, msg):
2008-09-18 23:32:30 +04:00
if msg == 'NT_STATUS_OBJECT_NAME_NOT_FOUND':
2008-05-26 07:12:31 +04:00
print "No active connections"
else:
show_sessions(conn)
show_tcons(conn)