Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 网站访问者(已访问URL)记录器应用程序_C#_Desktop Application - Fatal编程技术网

C# 网站访问者(已访问URL)记录器应用程序

C# 网站访问者(已访问URL)记录器应用程序,c#,desktop-application,C#,Desktop Application,我已经做了一个应用程序来记录当前PC用户访问的所有网站。这不是恶意使用。我正在为我的员工监控软件制作此功能,该软件将根据适当的法律获得许可 说到要点,每当我从任何浏览器(如IE)获取URL时,我只获取所有打开选项卡的URL。我无法获取IE7+的任何选项卡句柄,因此我无法维护已为同一选项卡记录URL的选项卡列表。 下面是我的代码(首先查看注释代码): 我提供了有关此主题的解决方案: 在这里,我使用了Java,但您也可以使用C。我几乎可以肯定,C#有很多很好的libpcap包装器 有一个名为pcap

我已经做了一个应用程序来记录当前PC用户访问的所有网站。这不是恶意使用。我正在为我的员工监控软件制作此功能,该软件将根据适当的法律获得许可

说到要点,每当我从任何浏览器(如IE)获取URL时,我只获取所有打开选项卡的URL。我无法获取IE7+的任何选项卡句柄,因此我无法维护已为同一选项卡记录URL的选项卡列表。 下面是我的代码(首先查看注释代码):


我提供了有关此主题的解决方案:

在这里,我使用了Java,但您也可以使用C。我几乎可以肯定,C#有很多很好的libpcap包装器

有一个名为pcapDotNet的项目,您可以使用它

调整一个示例:

using System;
using System.Collections.Generic;
using PcapDotNet.Core;
using PcapDotNet.Packets;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.Transport;

namespace InterpretingThePackets
{
    class Program
    {
        static void Main(string[] args)
        {
            // Retrieve the device list from the local machine
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];
                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                    Console.WriteLine(" (" + device.Description + ")");
                else
                    Console.WriteLine(" (No description available)");
            }

            int deviceIndex = 0;
            do
            {
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the device
            using (PacketCommunicator communicator = 
                selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                            // 65536 guarantees that the whole packet will be captured on all the link layers
                                    PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                    1000))                                  // read timeout
            {
                // Check the link layer. We support only Ethernet for simplicity.
                if (communicator.DataLink.Kind != DataLinkKind.Ethernet)
                {
                    Console.WriteLine("This program works only on Ethernet networks.");
                    return;
                }

                // Compile the filter
                using (BerkeleyPacketFilter filter = communicator.CreateFilter("ip and tcp"))
                {
                    // Set the filter
                    communicator.SetFilter(filter);
                }

                Console.WriteLine("Listening on " + selectedDevice.Description + "...");

                // start the capture
                communicator.ReceivePackets(0, PacketHandler);
            }
        }

        // Callback function invoked by libpcap for every incoming packet
        private static void PacketHandler(Packet packet)
        {
            // print timestamp and length of the packet
            Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " length:" + packet.Length);

            IpV4Datagram ip = packet.Ethernet.IpV4;

            //Do your magic here using HttpRequestDatagram
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用PcapDotNet.Core;
使用PcapDotNet.Packets;
使用PcapDotNet.Packets.IpV4;
使用PcapDotNet.Packets.Transport;
命名空间解释包
{
班级计划
{
静态void Main(字符串[]参数)
{
//从本地计算机检索设备列表
IList allDevices=LivePacketDevice.AllLocalMachine;
如果(allDevices.Count==0)
{
WriteLine(“没有找到接口!确保安装了WinPcap。”);
返回;
}
//打印列表
for(int i=0;i!=allDevices.Count;++i)
{
LivePacketDevice设备=所有设备[i];
Console.Write((i+1)+“+”设备名称);
如果(device.Description!=null)
Console.WriteLine(“+device.Description+”);
其他的
Console.WriteLine((无可用描述));
}
int deviceIndex=0;
做
{
Console.WriteLine(“输入接口号(1-”+allDevices.Count+)”);
字符串deviceIndexString=Console.ReadLine();
if(!int.TryParse(deviceIndexString,out deviceIndex)||
deviceIndex<1 | | deviceIndex>allDevices.Count)
{
deviceIndex=0;
}
}而(deviceIndex==0);
//使用选定的适配器
PacketDevice selectedDevice=所有设备[deviceIndex-1];
//打开设备
使用(PacketCommunicator communicator=
选择Device.Open(65536,//要捕获的数据包部分
//65536保证在所有链路层上捕获整个数据包
PacketDeviceOpenAttributes.Promiscuous,//Promiscuous模式
1000))//读取超时
{
//检查链路层。为了简单起见,我们只支持以太网。
if(communicator.DataLink.Kind!=DataLinkKind.Ethernet)
{
WriteLine(“此程序仅在以太网网络上工作。”);
返回;
}
//编译过滤器
使用(BerkeleyPacketFilter=communicator.CreateFilter(“ip和tcp”))
{
//设置过滤器
通信器。设置过滤器(过滤器);
}
Console.WriteLine(“监听”+所选设备描述+”);
//开始捕获
communicator.ReceivePackets(0,PacketHandler);
}
}
//libpcap为每个传入数据包调用的回调函数
专用静态void PacketHandler(数据包)
{
//打印数据包的时间戳和长度
Console.WriteLine(packet.Timestamp.ToString(“yyyy-MM-dd-hh:MM:ss.fff”)+“长度:”+“packet.length”);
IpV4数据报ip=packet.Ethernet.IpV4;
//在这里使用HttpRequestDatagram实现您的魔术
}
}
}

请查看注释后的代码,以便您了解情况。
using System;
using System.Collections.Generic;
using PcapDotNet.Core;
using PcapDotNet.Packets;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.Transport;

namespace InterpretingThePackets
{
    class Program
    {
        static void Main(string[] args)
        {
            // Retrieve the device list from the local machine
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];
                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                    Console.WriteLine(" (" + device.Description + ")");
                else
                    Console.WriteLine(" (No description available)");
            }

            int deviceIndex = 0;
            do
            {
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the device
            using (PacketCommunicator communicator = 
                selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                            // 65536 guarantees that the whole packet will be captured on all the link layers
                                    PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                    1000))                                  // read timeout
            {
                // Check the link layer. We support only Ethernet for simplicity.
                if (communicator.DataLink.Kind != DataLinkKind.Ethernet)
                {
                    Console.WriteLine("This program works only on Ethernet networks.");
                    return;
                }

                // Compile the filter
                using (BerkeleyPacketFilter filter = communicator.CreateFilter("ip and tcp"))
                {
                    // Set the filter
                    communicator.SetFilter(filter);
                }

                Console.WriteLine("Listening on " + selectedDevice.Description + "...");

                // start the capture
                communicator.ReceivePackets(0, PacketHandler);
            }
        }

        // Callback function invoked by libpcap for every incoming packet
        private static void PacketHandler(Packet packet)
        {
            // print timestamp and length of the packet
            Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " length:" + packet.Length);

            IpV4Datagram ip = packet.Ethernet.IpV4;

            //Do your magic here using HttpRequestDatagram
        }
    }
}