You will never be able to intercept network traffic just by inserting a class into your project. Packet capture functionality requires kernel mode support, hence you will at the very least need to have your application require or install libpcap/WinPcap, as Will Dean pointed out.
Most modern Unix-like distributions include libpcap out of the box, in which case you could take a look at this very simple example: http://www.tcpdump.org/pcap.htm
If you're using Windows, you're more or less on your own, although WinPcap programming is extremely similar to libpcap programming (unsurprisingly, since it's a libpcap port to Win32.) The SDK can be found here: http://www.winpcap.org/devel.htm
At any rate, no matter the operating system, you will need root / Administrator access to actually perform a capture. Just using the library to replay or analyze precaptured data doesn't require any special privilege, of course.
发布评论
评论(3)
仅通过将类插入项目中,您将永远无法拦截网络流量。 数据包捕获功能需要内核模式支持,因此您至少需要让您的应用程序需要或安装 libpcap/WinPcap,正如 Will Dean 指出的那样。
大多数现代类 Unix 发行版都包含开箱即用的 libpcap,在这种情况下,您可以看一下这个非常简单的示例: http://www.tcpdump.org/pcap.htm
如果您使用的是 Windows,则或多或少要靠自己,尽管 WinPcap 编程与 libpcap 编程极其相似(毫不奇怪,因为它是 Win32 的 libpcap 端口。)可以在此处找到 SDK:http://www.winpcap.org/devel.htm
无论如何,无论操作系统如何,您都会 需要 root/管理员访问权限才能实际执行捕获。 当然,仅使用该库重放或分析预先捕获的数据不需要任何特殊权限。
You will never be able to intercept network traffic just by inserting a class into your project. Packet capture functionality requires kernel mode support, hence you will at the very least need to have your application require or install libpcap/WinPcap, as Will Dean pointed out.
Most modern Unix-like distributions include libpcap out of the box, in which case you could take a look at this very simple example: http://www.tcpdump.org/pcap.htm
If you're using Windows, you're more or less on your own, although WinPcap programming is extremely similar to libpcap programming (unsurprisingly, since it's a libpcap port to Win32.) The SDK can be found here: http://www.winpcap.org/devel.htm
At any rate, no matter the operating system, you will need root / Administrator access to actually perform a capture. Just using the library to replay or analyze precaptured data doesn't require any special privilege, of course.
您需要介绍一下您的平台,因为这是一个平台而不是语言。
但假设您使用的是常见的东西,请查看 pcap 或 winpcap。
You'll need to say something about your platform, as this is a platform rather than a language thing.
But assuming you're on something common, look into pcap or winpcap.
Microsoft 网络监视器具有数据包捕获和分析 API,请参阅 netmon 博客 了解一些基本信息。
Microsoft Network Monitor has a packet capture and analysis API, see the netmon blog for some basic info.