Здравствуйте. Нужно вывести список открытых портов и приложений(служб) слушающих порты, кто что посоветует ?
Начиная с XP SP2 GetExtendedTcpTable. Раньше какой-то AllocateAndGetTcpExTableFromStack из iphlpapi.dll
У меня в 2k тоже есть. На sysinternals.com раньше был tcpview, он как раз эти две функции юзал GetExtendedUdpTable, GetExtendedTcpTable....
delphi http://slow.alfamoon.com/?module=filesdb&id=1&fid=13&get=1 для хрюши и старше AllocateAndGetTcpExTableFromStack, AllocateAndGetUdpExTableFromStack http://slow.alfamoon.com/?module=filesdb&id=1&fid=12&get=1 для 2к и старше по поводу tcpview у меня только часть кода есть Код (Text): nt NetstatMain ( CStringList& lstOutput) { char acBuf [ 1024]; HANDLE hTrapEvent; AsnObjectIdentifier hIdentifier; RFC1157VarBindList bindList; RFC1157VarBind bindEntry; UINT tcpidentifiers[] = { 1,3,6,1,2,1,6,13,1,1}; UINT udpidentifiers[] = { 1,3,6,1,2,1,7,5,1,1}; AsnInteger errorStatus, errorIndex; TCPINFO *currentEntry, *newEntry; UINT currentIndex; WORD wVersionRequested; WSADATA wsaData; char localname[HOSTNAMELEN], remotename[HOSTNAMELEN]; char remoteport[PORTNAMELEN], localport[PORTNAMELEN]; char localaddr[ADDRESSLEN], remoteaddr[ADDRESSLEN]; // // Initialize winsock // wVersionRequested = MAKEWORD( 1, 1 ); if( WSAStartup( wVersionRequested, &wsaData ) ) { return 1; } // // Locate and initialize INETMIB1 // if( !LoadInetMibEntryPoints()) { return 1; } if( !SnmpExtensionInit( GetCurrentTime(), &hTrapEvent, &hIdentifier )) { return 1; } // // Initialize the query structure once // bindEntry.name.idLength = 0xA; bindEntry.name.ids = tcpidentifiers; bindList.list = &bindEntry; bindList.len = 1; TcpInfoTable.prev = &TcpInfoTable; TcpInfoTable.next = &TcpInfoTable; // // Roll through TCP connections // currentIndex = 1; currentEntry = &TcpInfoTable; while(1) { if( !SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST, &bindList, &errorStatus, &errorIndex )) { return 1; } // // Terminate when we're no longer seeing TCP information // if( bindEntry.name.idLength < 0xA ) break; // // Go back to start of table if we're reading info // about the next byte // if( currentIndex != bindEntry.name.ids[9] ) { currentEntry = TcpInfoTable.next; currentIndex = bindEntry.name.ids[9]; } // // Build our TCP information table // switch( bindEntry.name.ids[9] ) { case 1: // // Always allocate a new structure // newEntry = (TCPINFO *) malloc( sizeof(TCPINFO )); newEntry->prev = currentEntry; newEntry->next = &TcpInfoTable; currentEntry->next = newEntry; currentEntry = newEntry; currentEntry->state = bindEntry.value.asnValue.number; break; case 2: currentEntry->localip = *(UINT *) bindEntry.value.asnValue.address.stream; currentEntry = currentEntry->next; break; case 3: currentEntry->localport = bindEntry.value.asnValue.number; currentEntry = currentEntry->next; break; case 4: currentEntry->remoteip = *(UINT *) bindEntry.value.asnValue.address.stream; currentEntry = currentEntry->next; break; case 5: currentEntry->remoteport = bindEntry.value.asnValue.number; currentEntry = currentEntry->next; break; } } // // Now print the connection information // sprintf(acBuf, "%7s %-30s %-30s %s\n", "Proto", "Local", "Remote", "State" ); lstOutput.AddTail ( new CString ( acBuf)); currentEntry = TcpInfoTable.next; while( currentEntry != &TcpInfoTable ) { sprintf( localaddr, "%s:%s", GetIpHostName( TRUE, currentEntry->localip, localname, HOSTNAMELEN), GetPortName( currentEntry->localport, "tcp", localport, PORTNAMELEN )); sprintf( remoteaddr, "%s:%s", GetIpHostName( FALSE, currentEntry->remoteip, remotename, HOSTNAMELEN), currentEntry->remoteip ? GetPortName( currentEntry->remoteport, "tcp", remoteport, PORTNAMELEN ): "0" ); sprintf(acBuf,"%7s %-30s %-30s %s\n", "TCP", localaddr, remoteaddr, TcpState[currentEntry->state]); lstOutput.AddTail ( new CString ( acBuf)); currentEntry = currentEntry->next; } // // Initialize the query structure once // bindEntry.name.idLength = 0xA; bindEntry.name.ids = udpidentifiers; bindList.list = &bindEntry; bindList.len = 1; UdpInfoTable.prev = &UdpInfoTable; UdpInfoTable.next = &UdpInfoTable; // // Roll through UDP endpoints // currentIndex = 1; currentEntry = &UdpInfoTable; while(1) { if( !SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST, &bindList, &errorStatus, &errorIndex )) { return 1; } // // Terminate when we're no longer seeing TCP information // if( bindEntry.name.idLength < 0xA ) break; // // Go back to start of table if we're reading info // about the next byte // if( currentIndex != bindEntry.name.ids[9] ) { currentEntry = UdpInfoTable.next; currentIndex = bindEntry.name.ids[9]; } // // Build our TCP information table // switch( bindEntry.name.ids[9] ) { case 1: // // Always allocate a new structure // newEntry = (TCPINFO *) malloc( sizeof(TCPINFO )); newEntry->prev = currentEntry; newEntry->next = &UdpInfoTable; currentEntry->next = newEntry; currentEntry = newEntry; currentEntry->localip = *(UINT *) bindEntry.value.asnValue.address.stream; break; case 2: currentEntry->localport = bindEntry.value.asnValue.number; currentEntry = currentEntry->next; break; } } // // Now print the connection information // currentEntry = UdpInfoTable.next; while( currentEntry != &UdpInfoTable ) { sprintf(acBuf, "%7s %s:%s\n", "UDP", GetIpHostName( TRUE, currentEntry->localip, localname, HOSTNAMELEN), GetPortName( currentEntry->localport, "udp", localport, PORTNAMELEN ) ); lstOutput.AddTail ( new CString ( acBuf)); currentEntry = currentEntry->next; } }