通过查找应用​​程序使用的TCP端口 [英] Finding tcp ports used by application

查看:248
本文介绍了通过查找应用​​程序使用的TCP端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我延长我公司的FLEXlm供应商守护程序是多一点点显露对客户端应用程序。

Alright, so I'm extending my company's flexlm vendor daemon to be a little bit more revealing to client applications.

我需要能够找出端口的lmgrd正在监听客户端连接之前。 API文档显得较​​为贫瘠,而且我相信他们保持在一个编译的形式大部分code,所以我不能只是看看他们的来源。

I need to be able to find out what port lmgrd is listening on before clients connect. The API documentation seems to be rather barren, and I believe they keep most of their code in a compiled form so I can't just look at their source.

是否有可能于Windows API的真棒权力打电话找出端口一个特定的进程正在使用?如果Sysinternals公司的Process Explorer可以做到这一点,我应该可以吧?有没有人有样code这个?

Is it possible to call upon the awesome power of the Windows API to find out what ports a particular process is using? If Process Explorer from sysinternals can do it, I should be able to right? Does anyone have sample code for this?

它需要支持Windows XP和因为我们的许多客户还没有升级为高。

It needs to support Windows XP and higher since many of our clients have yet to upgrade.

编辑:
我要指出,事实证明FLEX具有从许可文件将端口的支持。我没有在我面前的code,但知道这是不是找出你的供应商守护程序/程序lmgrd正在运行哪些端口的最佳方式。

I should note that it turns out FLEX has support for pulling the port from the license file. I don't have the code in front of me, but know that this isn't the best way to find out what ports your vendor daemon/lmgrd is running.

推荐答案

GetTcpTable2 - 见编辑

GetTcpTable2 -- see EDIT

http://msdn.microsoft.com /en-us/library/bb408406(v=vs.85).aspx

该GetTcpTable函数检索IPv4的TCP连接表。

The GetTcpTable function retrieves the IPv4 TCP connection table.

这将填补一个MIB_TCPTABLE结构。

This will fill in a MIB_TCPTABLE structure.

typedef struct _MIB_TCPTABLE {
  DWORD      dwNumEntries;
  MIB_TCPROW table[ANY_SIZE];
} MIB_TCPTABLE, *PMIB_TCPTABLE;

和现在MIB_TCPROW

And now the MIB_TCPROW

typedef struct _MIB_TCPROW {
  DWORD dwState;
  DWORD dwLocalAddr;
  DWORD dwLocalPort;
  DWORD dwRemoteAddr;
  DWORD dwRemotePort;
} MIB_TCPROW, *PMIB_TCPROW;

修改重要

您需要,以获得相关的,以及相应的PID使用GetTcpTable2。

You need to use GetTcpTable2 in order to get the corresponding PID associated as well.

typedef struct _MIB_TCPROW2 {
  DWORD                        dwState;
  DWORD                        dwLocalAddr;
  DWORD                        dwLocalPort;
  DWORD                        dwRemoteAddr;
  DWORD                        dwRemotePort;
  DWORD                        dwOwningPid;
  TCP_CONNECTION_OFFLOAD_STATE dwOffloadState;
} MIB_TCPROW2, *PMIB_TCPROW2;

dwOwningPid

dwOwningPid

这篇关于通过查找应用​​程序使用的TCP端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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