Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用打开的端口获取应用程序_C++_Windows_Ports - Fatal编程技术网

C++ 使用打开的端口获取应用程序

C++ 使用打开的端口获取应用程序,c++,windows,ports,C++,Windows,Ports,想要在我的电脑中获取使用已打开端口的应用程序。我使用gettcport检索已打开端口的列表 #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(

想要在我的电脑中获取使用已打开端口的应用程序。我使用
gettcport
检索已打开端口的列表

#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;
}
#pragma注释(lib,“iphlapi.lib”)
#pragma注释(lib,“ws2_32.lib”)
#定义地址大小(3+3*4+1)//xxx.xxx.xxx.xxx\0
字符常量*点(DWORD输入){
字符输出[地址大小];
sprintf(输出,“%d.%d.%d”,
输入>>24,
(输入>>16)和0xff,
(输入>>8)&0xff,
输入&0xff);
返回strdup(输出);
}
int main(){
MIB_TCPTABLE*tcp_stats=NULL;
MIB_UDPTABLE*udp_stats=NULL;
MIB_TCPROW2*a=NULL;
DWORD大小=0;
未签名的i;
字符常量*s1,*s2;
GetTcpTable(tcp_stats和size,TRUE);
tcp_stats=(MIB_TCPTABLE*)malloc(大小);
GetTcpTable(tcp_stats和size,TRUE);
printf(“les端口:”);
对于(i=0;idwNumEntries;++i){
printf(“TCP:\t:%d\n”,
ntohs(tcp_stats->table[i].dwLocalPort);
}
免费(tcp_统计数据);
系统(“暂停”);
返回0;
}

但是,,我想获取使用每个端口的应用程序。

在Vista和上面,从中返回的连接表中的每个
MIB\u TCPROW2
行都有一个
dwOwningPid
成员,该成员包含创建进程的进程标识符。

在Vista和上面,从中返回的连接表中的每个
MIB\u TCPROW2
行具有包含创建进程的进程标识符的
dwOwningPid
成员。

您可以使用WMI类
Win32\u进程
您可以使用WMI类
Win32\u进程

否。可能是XP sp2+Nope上的
GetExtendedTcpTable
。可能是XP sp2上的
GetExtendedTcpTable
+