1
我使用此代碼獲取打開的UDP端口和使用每個端口的應用程序。GetExtendedUdpTable和netstat結果之間的區別
DWORD (WINAPI *pGetExtendedUdpTable)(
PVOID pUdpTable,
PDWORD pdwSize,
BOOL bOrder,
ULONG ulAf,
UDP_TABLE_CLASS TableClass,
ULONG Reserved
);
MIB_UDPTABLE_OWNER_PID *pUDPInfo;
MIB_UDPROW_OWNER_PID *owner;
DWORD size;
DWORD dwResult;
HMODULE hLib = LoadLibrary((LPCWSTR)"iphlpapi.dll");
pGetExtendedUdpTable = (DWORD (WINAPI *)(PVOID,PDWORD,BOOL,ULONG,UDP_TABLE_CLASS,ULONG))
GetProcAddress(hLib, "GetExtendedTcpTable");
if (!pGetExtendedUdpTable)
{
//printf("Could not load iphlpapi.dll. This application is for Windows XP SP2 and up.\n");
return "Could not load iphlpapi.dll. This application is for Windows XP SP2 and up.\n";
}
dwResult = pGetExtendedUdpTable(NULL, &size, false, AF_INET, (UDP_TABLE_CLASS)5, 0);
pUDPInfo = (MIB_UDPTABLE_OWNER_PID*)malloc(size);
dwResult = pGetExtendedUdpTable(pUDPInfo, &size, false, AF_INET, (UDP_TABLE_CLASS)5, 0);
//
if (dwResult != NO_ERROR)
{
printf("Couldn't get our IP table");
return "Couldn't get our IP table";
}
for (DWORD dwLoop = 0; dwLoop < pUDPInfo->dwNumEntries; dwLoop++)
{
owner = &pUDPInfo->table[dwLoop];
ApplicationName = GetNameByPID(owner->dwOwningPid);
OpenedPort = convertInt(ntohs(owner->dwLocalPort));
LocalAdress = convertInt(ntohs(owner->dwLocalAddr));
}
不過,我也沒有相同的結果,netstat的-ano.In我的代碼,我有口0超過10次,但在netstat命令端口0不存在。