Windows进程和IP地址,它是连接到 [英] Windows Process and Ip Address that it's connected to

查看:801
本文介绍了Windows进程和IP地址,它是连接到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个进程连接到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:

  1. 使用无证 InternalGetTcpTableWithOwnerModule / InternalGetUdpTableWithOwnerModule / InternalGetTcp6TableWithOwnerModule / InternalGetUdp6TableWithOwnerModule 的API从IPHLPAPI.DLL出口。
  2. 运行的netstat -b 和解析输出。
  1. Use the undocumented InternalGetTcpTableWithOwnerModule / InternalGetUdpTableWithOwnerModule / InternalGetTcp6TableWithOwnerModule / InternalGetUdp6TableWithOwnerModule APIs exported from iphlpapi.dll.
  2. 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屋!

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