0

如何打印在我的共享文件夹中删除文件的客户端电脑的 IP 或主机名?此代码有效,但它只打印我自己的 IP 和主机名,而不是在我的共享文件夹中删除文件的另一台电脑。我使用Centos 6.3。我使用Samba共享我的文件夹。我使用Python 2.7PYinotify脚本。

这是我的代码

import pyinotify

wm = pyinotify.WatchManager()

mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE

class EventHandler(pyinotify.ProcessEvent):

    def process_IN_CREATE(self, event): 
    print "",now.strftime("%b-%d-%Y @ %I:%M %p"),"  "   ,socket.gethostname()," ","Create ","  ",event.name,"  ",event.path

    def process_IN_DELETE(self, event):
    print "",now.strftime("%b-%d-%Y @ %I:%M %p"),"  "    ,socket.gethostname()," ","Shift+Del","",event.name," ",event.path

handler = EventHandler()

notifier = pyinotify.Notifier(wm, handler)

wdd = wm.add_watch('/echoshare', mask, rec=True)

auto_add = '/echoshare'

notifier.loop()
4

1 回答 1

1

我认为您误解了 (py)inotify 是什么。这是一种监视文件系统事件的方法,您将获得有关 samba 服务器在本地文件系统上完成的操作的信息。

如果您查看inotify 文档,您会注意到 inotify_event 结构不包含有关用户执行操作的任何信息。

我想对您的问题最简单的解决方案是在您的 samba 服务器上启用事件日志记录并解析生成的事件以获取您想要的信息

于 2012-11-29T14:06:10.193 回答