如何创建一个简单的c#http monitor / blocker? [英] How to create a simple c# http monitor/blocker?

查看:148
本文介绍了如何创建一个简单的c#http monitor / blocker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这个问题(如何创建一个简单的代理C#?)接近我的意愿。

I was reading that question (How to create a simple proxy in C#?) that is near of my wishes.

我只想开发ac#app,例如,监控Firefox,IE等,并记录所有导航页面。根据访问过的页面,我想阻止该网站(如父母过滤器)。

I simply want develop a c# app that, by example, monitors Firefox, IE, etc and logs all navigated pages. Depending of the visited page, I want to block the site (like a parental filter).

代码片段/样本很好,但如果你能告诉我某个方向对那些课程的使用我将不胜感激。 : - )

Code snippets/samples are good, but if you can just tell me some direction of that classes to use I will be grateful. :-)

推荐答案

我会回答适合父母:ala家长控制

I’ll answer appropriate for a parent: ala "Parental Controls"

当孩子小于10岁时,您可以从代理服务器开始。之后,他们将弄清楚如何绕过代理(或运行绕过代理的自己的客户端应用程序)。在青少年时期,您可以使用原始套接字。
将此程序键入Visual Studio(C#)。

You can start out with a proxy server when the kids are less than about 10 years old. After that, they will figure out how to get around the proxy (or run their own client applications that bypass the proxy). In the early teen years, you can use raw sockets. Type this program into Visual Studio (C#).

class Program
{
    static void Main(string[] args)
    {
        try
        {
            byte[] input = BitConverter.GetBytes(1);
            byte[] buffer = new byte[4096];
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
            s.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.91"), 0));
            s.IOControl(IOControlCode.ReceiveAll, input, null);

            int bytes = 0;
            do
            {
                bytes = s.Receive(buffer);
                if (bytes > 0)
                {
                    Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytes));
                }
            } while (bytes > 0);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
}

请注意,这只是一个片段,缺乏适当的设计和错误检查。 [请不要使用'原样' - 您确实要求只是一个开头]更改您的机器的IP地址。运行程序 AS Administrator (在命令行上使用runas,或右键单击以管理员身份运行)。只有管​​理员才能在现代版本的Windows上创建和使用原始套接字。坐下来观看节目。

Note that this is just a "snippet", lacking appropriate design and error checking. [Please do not use 'as-is' - you did request just a head start] Change the IP address to your machine. Run the program AS Administrator (use "runas" on the command line, or right-click "Run as Administrator"). Only administrators can create and use raw sockets on modern versions of windows. Sit back and watch the show.

所有网络流量都会传递给您的代码(显示在屏幕上,使用此程序看起来不太好。)

All network traffic is delivered to your code (displayed on the screen, which will not look nice, with this program).

下一步是创建一些协议过滤器。了解各种互联网应用程序协议(假设您还不知道),修改程序以检查数据包。查找HTTP协议,并保存适当的数据(如GET请求)。

Your next step is to create some protocol filters. Learn about the various internet application protocols (assuming you don't already know), modify the program to examine the packets. Look for HTTP protocol, and save the appropriate data (like GET requests).

我个人已经为AIM(AOL Instant Messenger),HTTP,MSN信使(Windows Live Messenger),POP和SMTP设置了过滤器。今天,HTTP得到了几乎所有东西,因为现在孩子们更喜欢Facebook墙到AIM。

I personally have setup filters for AIM (AOL Instant Messenger), HTTP, MSN messenger (Windows Live Messenger), POP, and SMTP. Today, HTTP gets just about everything since the kids prefer the facebook wall to AIM nowadays.

当孩子们到达青少年早期和中期时,你会想要监测的后退。有人说这是为了让孩子们长大,但真正的原因是 你不想知道 。我回过头来收集获取请求的URL,以及明文(pop,basic auth等)的用户名/密码(用于紧急情况)。

As the kids reach their early-to-mid teenage years, you will want to back-off on the monitoring. Some say this is to enable the kids to "grow up", but the real reason is that "you don’t wanna know". I backed off to just collecting URLs of get requests, and username/passwords (for emergency situations) that are in clear text (pop, basic auth, etc.).

我不知道青少年时期会发生什么;我无法想象事情变得更糟,但我被告知我还没有看到任何东西。

I don't know what happens in late teen years; I cannot image things getting much worse, but I am told that "I have not seen anything yet".

就像先前所说的那样,这只适用于在目标上运行的情况机器(我在房子里的所有机器上运行一份副本)。否则,为了简单的监控检查你的路由器 - 我的一些很好的日志功能。

Like someone earlier said, this only works when run on the target machine (I run a copy on all of the machines in the house). Otherwise, for simple monitoring check your router - mine has some nice logging features.

我的最后评论是这个应用程序应该用C / C ++直接用Win32 API编写,并作为在计算机上运行管理权限的服务安装。我不认为这种类型的代码适合托管c#。您可以在C#中附加UI以进行监视和控制。您必须设计代码才能对系统产生明显的影响。

My final comment is that this application should be written in C/C++ against the Win32 API directly, and installed as a service running with administrative rights on the machine. I don't think this type of code is appropriate for managed c#. You can attach a UI in C# for monitoring and control. You have to engineer the code so as to have zero noticeable effect on the system.

这篇关于如何创建一个简单的c#http monitor / blocker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆