Windows 上套接字号的 PID?

发布于 2024-07-19 06:33:37 字数 1362 浏览 4 评论 0原文

我需要计算各种应用程序从网络发送和接收的字节数。 首先我考虑使用LSP,但是有很多应用程序不使用LSP全部(SMB 例如)。 这就是为什么我写了一个小嗅探器。 该应用程序在 IP 级别上工作,并使用 recvfrom 收集数据。

所以我有远程主机的地址、本地和远程端口。 这很酷,但我还需要本地套接字所有者的 PID。 那么,有没有一种简单的方法来获取这样的PID呢?

解决方法是使用 GetTcpTable、GetUdpTable 或 AllocateAndGetUdpExTableFromStack 和 AllocateAndGetTcpExTableFromStack(Windows 2000 之间的这些函数有很多差异Windows XPWindows XP SP2Windows Vista)并查找结果表,但这似乎不优雅且效率低下......

那么是否有一种“GetPIDOfSocket”函数? 分辨率应为 Win32(不 Win32) org/wiki/.NET_Framework" rel="nofollow noreferrer">.NET) 仅限,因为可以使用各种语言,例如 C++ 和 德尔福

I need to count amount of bytes sent and received from the network by various applications. First I thought about using LSP, but there is a lot of applications that do not use LSP at all (SMB for example). This is why I have written a small sniffer. This application works on the IP level and collects data using recvfrom.

So I have the address of the remote host, local and remote ports. This is pretty cool, but I also need to have the PID of the local socket owner. So, is there a simple way to obtain such PID?

The workaround is using GetTcpTable, GetUdpTable Or AllocateAndGetUdpExTableFromStack and AllocateAndGetTcpExTableFromStack (there are a lot of differences in those functions between Windows 2000, Windows XP, Windows XP SP2 and Windows Vista) and to lookup result tables, but it seems inelegant and inefficient...

So is there a kind of A "GetPIDOfSocket" function? The resolution should be Win32 (no .NET) only, as various languages can be used, e.g. C++ and Delphi.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2024-07-26 06:33:37

使用 GetTcpTableAllocateAndGetTcpExTableFromStack 不是解决方法。 这实际上是其他netstat类型应用程序的工作方式。

据我所知,没有任何 Win32 "GetPIDOfSocket" 函数。 您唯一的选择是使用端口表功能进行轮询。 但至少您可以自己编写代码,而不必生成 netstat 进程。

请参阅 Sysinternals netstatp 的 C 源代码 此处。 内容不多,但很值得一看。

Using GetTcpTable or AllocateAndGetTcpExTableFromStack is not a workaround. It's actually how other netstat-type applications work.

As far as I know, there isn't any Win32 "GetPIDOfSocket" function. Your only option is to poll using the port table functions. But at least you can code it up yourself and don't have to spawn the netstat process.

See the Sysinternals C source code for netstatp here. There's not a lot of it and it's well worth a look.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文