[英]Python cannot print the client IP or client hostname
How can I print the IP or hostname of the client pc who delete a file in my shared folder?This code is working but it only print my own IP and Hostname not the other pc that delete a file inside my shared folder. 我该如何打印删除共享文件夹中文件的客户端PC的IP或主机名?此代码有效,但它仅打印我自己的IP和主机名,而不打印其他删除共享文件夹中文件的PC。 Im using Centos 6.3 .I use Samba to share my folder.I use Python 2.7 and PYinotify script. 我使用Centos 6.3 。我使用Samba共享文件夹。我使用Python 2.7和PYinotify脚本。
This is my code 这是我的代码
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()
I think you misunderstand what (py)inotify is. 我认为您误解了(py)inotify是什么。 It is a way to monitor filesystem events and you will get information about operations done by samba server on local filesystem. 这是一种监视文件系统事件的方法,您将获得有关samba服务器在本地文件系统上完成的操作的信息。
If you take a look on inotify documentation you will notice that inotify_event structure does not carry any information about user performing the operations. 如果查看inotify文档,您会注意到inotify_event结构不包含有关用户执行操作的任何信息。
I guess a simplest solution to you problem would be to enable event logging on your samba server and parse generated events for information you want 我想最简单的解决方案是在samba服务器上启用事件日志记录并解析生成的事件以获取所需信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.