Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/08/2013, 22:27
EL_DOC
 
Fecha de Ingreso: junio-2008
Mensajes: 109
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: Obtener puertos abiertos TCP/IP por cada programa

Buscando en la red encontré un código de alguien que está haciendo casi lo mismo pero hay ciertas cosas que no logro comprender del código si alguien me ayuda a comprender el código se los agradecería, el código es el siguiente:

string Port::GetListOfTcpPorts()

{
string ApplicationName = "";
string result = "";
string aux = "";
string RemotePort = "";
DWORD (WINAPI *pGetExtendedTcpTable)(
PVOID pTcpTable,
PDWORD pdwSize,
BOOL bOrder,
ULONG ulAf,
TCP_TABLE_CLASS TableClass,
ULONG Reserved
);
MIB_TCPTABLE_OWNER_PID *pTCPInfo;
MIB_TCPROW_OWNER_PID *owner;
DWORD size;
DWORD dwResult;

HMODULE hLib = LoadLibrary("iphlpapi.dll");

pGetExtendedTcpTable = (DWORD (WINAPI *)(PVOID,PDWORD,BOOL,ULONG,TCP_TABLE_CLASS,ULONG))
GetProcAddress(hLib, "GetExtendedTcpTable");

dwResult = pGetExtendedTcpTable(NULL, &size, false, AF_INET, TCP_TABLE_OWNER_PID_LISTENER, 0);
pTCPInfo = (MIB_TCPTABLE_OWNER_PID*)malloc(size);
dwResult = pGetExtendedTcpTable(pTCPInfo, &size, false, AF_INET, TCP_TABLE_OWNER_PID_LISTENER, 0);
for (DWORD dwLoop = 0; dwLoop < pTCPInfo->dwNumEntries; dwLoop++)
{
owner = &pTCPInfo->table[dwLoop];
ApplicationName = GetNameByPID(owner->dwOwningPid);
OpenedPort = convertInt(ntohs(owner->dwLocalPort));
RemotePort = convertInt(ntohs(owner->dwRemotePort));
aux = "TCP ; " + OpenedPort + ";"+ RemotePort+";"+ ApplicationName + "\n";
result = result + aux;

}
return result;
}