c++ - Get applications using opened ports -


want applications use opened ports in pc. used gettcpport retrieve list of opened ports

#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 :");     (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; } 

but, want application use each port.

you can use wmi class win32_process http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372(v=vs.85).aspx


Comments