如何枚举给定 Windows 进程上的套接字? [英] How can I enumerate sockets on a given windows process?

查看:46
本文介绍了如何枚举给定 Windows 进程上的套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的程序来检查给定的 Windows 进程是否正在滥用网络.我想枚举进程 tcp 和 udp 套接字,看看它们在给定时间段内传输了多少数据.

I need my program to check if a given Windows process is abusing the network. I would like to enumerate the process tcp and udp sockets, and see how much data they transferred during a given period.

是否有 C 或 .Net API 可以提供此类信息?

Is there a C or .Net API that can provide such info?

推荐答案

在 Win2k 上,您可以使用 GetTcpTable()、GetTcp6Table()、GetUdpTable() 和 GetUdp6Table() 来定位所有活动的套接字连接.但是要将它们与特定的进程 ID 匹配,您必须手动枚举系统的打开句柄以查找 TCP/UDP 句柄,然后从中查询进程信息.

On Win2k, you can use GetTcpTable(), GetTcp6Table(), GetUdpTable(), and GetUdp6Table() to locate all of the active socket connections. But to match them to specific process IDs, you would have to manually enumerate the system's open handles looking for TCP/UDP handles, and then query the process information from them.

在 XP 上,您可以使用 AllocateAndGetTcpExTableFromStack() 和 AllocateAndGetUdpExTableFromStack(),它们可以返回每个套接字连接的进程 ID.

On XP, you can use AllocateAndGetTcpExTableFromStack() and AllocateAndGetUdpExTableFromStack(), which can return process IDs with each socket connection.

在 XP SP2 及更高版本上,您可以使用 GetExtendedTcpTable() 和 GetExtendedUdpTable(),它们也可以返回每个套接字连接的进程 ID.

On XP SP2 and later, you can use GetExtendedTcpTable() and GetExtendedUdpTable(), which can return process IDs with each socket connection as well.

这篇关于如何枚举给定 Windows 进程上的套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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