使用打开的端口获取应用程序
Get applications using opened ports
想要获取在我的电脑中使用打开端口的应用程序。我使用GetTcpPort
检索打开端口的列表
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#define addr_size (3 + 3*4 + 1) // xxx.xxx.xxx.xxx
char const *dotted(DWORD input) {
char output[addr_size];
sprintf(output, "%d.%d.%d.%d",
input>>24,
(input>>16) & 0xff,
(input>>8)&0xff,
input & 0xff);
return strdup(output);
}
int main() {
MIB_TCPTABLE *tcp_stats = NULL;
MIB_UDPTABLE *udp_stats = NULL;
MIB_TCPROW2 *a = NULL;
DWORD size = 0;
unsigned i;
char const *s1, *s2;
GetTcpTable(tcp_stats, &size, TRUE);
tcp_stats = (MIB_TCPTABLE *)malloc(size);
GetTcpTable(tcp_stats, &size, TRUE);
printf("les ports :");
for (i=0; i<tcp_stats->dwNumEntries; ++i) {
printf("TCP:t:%dn",
ntohs(tcp_stats->table[i].dwLocalPort));
}
free(tcp_stats);
system("pause");
return 0;
}
但是,我想得到使用每个端口的应用程序。
您可以使用WMI类Win32_Process
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372(v=vs.85(.aspx
在Vista及以上版本中,从GetTcpTable2
返回的连接表中的每一行MIB_TCPROW2
都有一个dwOwningPid
成员,该成员包含创建进程的进程标识符。
相关文章:
- 在C++中获取应用程序窗口的大小
- 如何从二进制文件中获取应用程序的版本号?
- 获取应用程序图标时出现问题
- 如何以编程方式获取应用程序的内存使用情况
- Windows编程:为什么我们要将lParam转换为CREATESTRUCT来获取应用程序状态
- 获取应用程序窗口的完整目录
- 获取"应用程序名称"以及按键
- 获取应用程序的内存使用情况时出错
- 正在从应用程序中获取应用程序版本
- 如何在安卓版Qt上获取应用程序参数
- 在 Linux 上的 Qt 中获取应用程序图标 URL
- 从任务管理器获取应用程序故障转储中显示的状态在 Windows 上是否准确
- Boost选项-获取应用程序名称
- CAppModule与CAtlExeModuleT,获取应用程序消息循环
- 如何获取应用程序的所有鼠标事件
- 获取应用程序运行实例的句柄
- 在Qt中获取应用程序外部的键盘事件
- 如何在GetModuleFileName (Win32 API)中使用POCO获取应用程序文件名
- 使用打开的端口获取应用程序
- Win32-获取应用程序的主Wnd句柄