以独立于浏览器的方式查看用户正在访问哪个网站
我正在尝试构建一个应用程序,每当用户访问我的数据库中存在的网站时,该应用程序都可以向用户通报网站的特定信息。这必须以独立于浏览器的方式完成,以便用户在访问网站时始终可以看到信息(无论他或她使用什么浏览器或其他工具来访问网站)。
我的第一个(部分成功)方法是使用 System.Net.Sockets.Socket 类等查看数据包。不幸的是,我发现这种方法仅在用户具有管理员权限时才有效。当然,这不是我想要的。我的目标是用户可以安装一个相对简单且可以立即使用的程序。
此后,我开始寻找替代方案,发现了很多有关 WinPcap 和其中一些 .NET 包装器的信息(我是否告诉过你我已经在进行 c# .NET 编程了?)。但是使用 WinPcap 我发现它必须安装在用户的电脑上,并且没有办法只引用一些 dll 文件和代码。我已经考虑过将 WinPcap 作为安装程序的先决条件,但这也很麻烦。
好吧,长话短说。我想在我的应用程序中知道我的用户正在访问哪个网站。我认为必须通过查看网络的数据包来完成,但找不到一个好的解决方案。我的应用程序是用 C# .NET (4.0) 构建的。
I am trying to build an application that can inform a user about website specific information whenever they are visiting a website that is present in my database. This must be done in a browser independent way so the user will always see the information when visiting a website (no matter what browser or other tool he or she is using to visit the website).
My first (partially successful) approach was by looking at the data packets using the System.Net.Sockets.Socket class etc. Unfortunately I discoverd that this approach only works when the user has administrator rights. And of course, that is not what I want. My goal is that the user can install one relatively simple program that can be used right away.
After this I went looking for alternatives and found a lot about WinPcap and some of it's .NET wrappers (did I tell you I am programming c# .NET already?). But with WinPcap I found out that this must be installed on the user's pc and there is nog way to just reference some dll files and code away. I already looked at including WinPcap as a prerequisite in my installer but that is also to cumbersome.
Well, long story short. I want to know in my application what website my user is visiting at the moment it is happening. I think it must be done by looking at the data packets of the network but can't find a good solution for this. My application is build in C# .NET (4.0).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 Fiddler 来监控互联网流量。
这是
它是可编写脚本的,并且可以轻松从.NET使用。
You could use Fiddler to monitor Internet traffic.
It is
It's scriptable and can be readily used from .NET.
一个简单的想法:与其直接监控流量,不如安装一个浏览器扩展来向您发送页面的当前 URL。然后,您可以检查该 URL 是否在您的数据库中,并可以选择使用浏览器扩展向用户显示一条消息。
这就是像 Invisible Hand 这样的扩展的工作原理...它扫描当前页面并将相关数据发送回服务器进行加工。如果发现任何内容,它会使用浏览器扩展框架将这些结果传达给用户。 (使用警报或窗口顶部的栏等)
One simple idea: Instead of monitoring the traffic directly, what about installing a browser extension that sends you the current url of the page. Then you can check if that url is in your database and optionally show the user a message using the browser extension.
This is how extensions like Invisible Hand work... It scans the current page and sends relevant data back to the server for processing. If it finds anything, it uses the browser extension framework to communicate those results back to the user. (Using an alert, or a bar across the top of the window, etc.)
作为一个良好的开始,wireshark 会做你想做的事。
您可以指定一个过滤器来隔离和查看 http 流。
最好的部分是,wireshark 是开源的,并且基于另一个开源程序 api winpcap 构建。
我猜这就是你想要的。
数 1 的信息很容易,您可以在 google 上搜索 winpcap 教程,或者只是使用他们的一些示例程序来捕获数据。
我建议您学习 pcap 文件格式,winpcap 的所有内容都使用这种基本格式及其结构。
现在您必须学习如何获取 TCP 流并将其转换为可靠的数据流,而无需使用 CurOption 或混乱的部分。 (抱歉拼写错误)
同样,在wireshark源代码中可以找到一个非常好的例子。
然后使用您的数据流,您可以简单地读取http格式和html数据,或者您处理的任何内容。
希望有帮助
for a good start, wireshark will do what you want.
you can specify a filter to isolate and view http streams.
best part is wireshark is open source, and built opon another program api, winpcap which is open source.
I'm guessing this is what you want.
number 1 there is easy, you can google for a winpcap tutorial, or just use some of their sample programs to capture the data.
I recomend you study up on the pcap file format, everything with winpcap uses this basic format and its structers.
now you have to learn how to take a tcp stream and turn it into a solid data stream without curoption, or disorginized parts. (sorry for the spelling)
again, a very good example can be found in the wireshark source code.
then with your data stream, you can simple read the http format, and html data, or what ever your dealing with.
Hope that helps
如果用户愿意合作,您可以让他们将浏览器设置为使用您提供的代理服务。这将拦截所有网络流量,对其执行任何您想要的操作(在数据库中查找、通知用户等),然后将其传递到原始位置。在本地系统上运行代理,如果更适合您的情况,也可以在远程系统上运行代理。
如果用户不合作,或者您不想让他们更改浏览器设置,您可以使用其中一种数据包嗅探解决方案,例如 fiddler。
If the user is cooperating, you could have them set their browser(s) to use a proxy service you provide. This would intercept all web traffic, do whatever you want with it (look up in your database, notify the user, etc), and then pass it on to the original location. Run the proxy on the local system, or on a remote system if that fits your case better.
If the user is not cooperating, or you don't want to make them change their browser settings, you could use one of the packet sniffing solutions, such as fiddler.
一种简单直接的方法是更改计算机 DNS 以指向您的应用程序。
这将导致所有 DNS 流量通过您的应用程序,该应用程序可以被嗅探,然后重定向到真正的 DNS 服务器。
它还可以为您节省过滤 emule/torrent 流量的麻烦,因为它通常使用纯 IP 地址(这也可能是一个问题,因为可以通过使用 IP 地址浏览来规避)。
-如何更改 Windows DNS 服务器
-DNS 解析器
另一种简单的方法是配置(以编程方式)浏览器代理以通过您的服务器这将使您的生活更轻松,但对用户来说更加明显。
A simple stright forward way is to change the comupter DNS to point to your application.
this will cause all DNS traffic to pass though your app which can be sniffed and then redirected to the real DNS server.
it will also save you the hussel of filtering out emule/torrent traffic as it normally work with pure IP address (which also might be a problem as it can be circumvented by using IP address to browse).
-How to change windows DNS Servers
-DNS resolver
Another simple way is to configure (programmaticly) the browsers proxy to pass through your server this will make your life easier but will be more obvious to users.