Windows进程和IP地址,它是连接到 [英] Windows Process and Ip Address that it's connected to
问题描述
我试图让一个进程连接到C#中的ip地址。有没有一种简单的方法来做到这一点?
I'm trying to get the ipaddress that a process is connected to in c#. Is there an easy way to do this?
推荐答案
有两种方法来实现这一点:
There are two ways to achieve this:
- 使用无证
InternalGetTcpTableWithOwnerModule
/InternalGetUdpTableWithOwnerModule
/InternalGetTcp6TableWithOwnerModule
/InternalGetUdp6TableWithOwnerModule
的API从IPHLPAPI.DLL出口。 - 运行
的netstat -b
和解析输出。
- Use the undocumented
InternalGetTcpTableWithOwnerModule
/InternalGetUdpTableWithOwnerModule
/InternalGetTcp6TableWithOwnerModule
/InternalGetUdp6TableWithOwnerModule
APIs exported from iphlpapi.dll. - Run
netstat -b
and parse the output.
无论哪种方式,您将需要管理员权限,而这两种方式都绑定到不同的Windows版本的破解。这是最有可能的,以创建一个Windows驱动程序与文档化API,但是这将是一个大量的工作。
Either way you will need administrator privileges and both ways are bound to break with different Windows versions. It is most certainly possible to create a Windows driver with documented APIs, but that would be a lot of work.
更新:
其实是有记录的API太 - GetExtendedTcpTable 和 GetExtendedUdpTable 。另外有一个文章其中presents一个例子,如何调用它从C#。
There is actually a documented API too - GetExtendedTcpTable and GetExtendedUdpTable. Also there's an article which presents an example how to call it from C#.
这篇关于Windows进程和IP地址,它是连接到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!