想要獲取使用我的PC中打開的端口的應用程序。我以前GetTcpPort
檢索開放的端口使用打開的端口獲取應用程序
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#define addr_size (3 + 3*4 + 1) // xxx.xxx.xxx.xxx\0
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:%d\n",
ntohs(tcp_stats->table[i].dwLocalPort));
}
free(tcp_stats);
system("pause");
return 0;
}
的列表,但是,我想使用的每個端口的應用程序。
GetTcpTable2可與XP? – Bacem 2013-03-21 14:40:33
沒有。也許在XP SP2上的'GetExtendedTcpTable' http://stackoverflow.com/questions/6499845/finding-tcp-ports-used-by-application – 2013-03-21 14:56:33