views:

444

answers:

4

Just wondering if it is possible to figure out who has read files from a Windows share (using .NET ideally but win32 native will do)?

What I'm try to do is create something like awstats for a windows share so I can see who is accessing what and which are the most popular files.

I'm not interested in changes - I just want to log access (with time) along with ip / hostname and what file.

+2  A: 

You want FileSystemWatcher. Build a program that uses it and logs changes.

Randolpho
one problem with this solution is the that the buffer can fill and lose some data...
chills42
I'm not interested in changes - I just want to log access (with time) along with ip / hostname and what file.
Ravi
Thanks for the suggestion but I've checked out FileSystemWatcher and doesn't seem to differentiate between network and local access.
Ravi
FileSystemWatcher doesn't audit, which is what this user basically wants to do. What you should consider is enabling auditing and simply monitoring the Event Log.http://support.microsoft.com/kb/814595That would be a reliable start.
Nissan Fan
@Nissan Fanlooks like that only works for Windows Server editions. I'm almost tempted to compile samba in Windows and parse log files from that.
Ravi
+2  A: 

Hi,

this is possible using WMI... below the sample c# snippet used to identify whose accessing the shares currenlty

using System.Management;
 ManagementObjectSearcher search =
             new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_ConnectionShare"); 
        foreach (ManagementObject MO in search.Get())
        {
            string antecedent = MO["antecedent"].ToString();
            ManagementObject share = new ManagementObject(antecedent);


            string dependent = MO["dependent"].ToString();
            ManagementObject server = new ManagementObject(dependent);


            string userName = server["UserName"].ToString();
            string compname = server["ComputerName"].ToString();
            string sharename = server["ShareName"].ToString();
        }

Am not sure about the core file event listners for WMI. But you can nicely integrate this into the NoramlFileSystemWatcher. And trigger the above code if there is a change detected in the network path.

Cheers

Ramesh Vel

Ramesh Vel
+1  A: 

SMB runs by default on port 445. So you can just log traffic on port 445 (or whatever port(s) you happen to be running it on) and massage that easily enough into whatever data you need.

I'd do it with WinPcap and WinDump (Windows versions of libpcap and tcpdump). Defining custom rules (say, to record data on only one or on a range of ports) is easy. Check out the 'expression' section of the manual. There are parsers available in a lot of different languages for the data files. A quick search will find you what you need.

Sam DeFabbia-Kane
A: 

In order to do it using WinPcap in .NET you can use Pcap.Net. It is a wrapper for WinPcap written in C++/CLI and C# and it includes a packet interpretation framework.

brickner