Поиск процессов с открытыми портами

Тема в разделе "WASM.NETWORKS", создана пользователем WIN32, 22 янв 2007.

  1. WIN32

    WIN32 Member

    Публикаций:
    0
    Регистрация:
    20 янв 2007
    Сообщения:
    338
    Здравствуйте.
    Нужно вывести список открытых портов и приложений(служб) слушающих порты, кто что посоветует ?
     
  2. Sharp

    Sharp New Member

    Публикаций:
    0
    Регистрация:
    1 авг 2003
    Сообщения:
    143
    Адрес:
    Ukraine
    Начиная с XP SP2 GetExtendedTcpTable. Раньше какой-то AllocateAndGetTcpExTableFromStack из iphlpapi.dll
     
  3. Proteus

    Proteus Member

    Публикаций:
    0
    Регистрация:
    19 июн 2004
    Сообщения:
    344
    Адрес:
    Russia
    У меня в 2k тоже есть. На sysinternals.com раньше был tcpview, он как раз эти две функции юзал GetExtendedUdpTable, GetExtendedTcpTable....
     
  4. WIN32

    WIN32 Member

    Публикаций:
    0
    Регистрация:
    20 янв 2007
    Сообщения:
    338
    Proteus
    Если остались сорцы, скинь пожалуйста clickf1@xakep.kz
     
  5. slow

    slow New Member

    Публикаций:
    0
    Регистрация:
    27 дек 2004
    Сообщения:
    615
    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 у меня только часть кода есть :dntknw:

    Код (Text):
    1. nt NetstatMain ( CStringList& lstOutput)
    2. {
    3.     char                    acBuf [ 1024];
    4.     HANDLE                  hTrapEvent;
    5.     AsnObjectIdentifier     hIdentifier;
    6.     RFC1157VarBindList      bindList;
    7.     RFC1157VarBind          bindEntry;
    8.     UINT                    tcpidentifiers[] = { 1,3,6,1,2,1,6,13,1,1};
    9.     UINT                    udpidentifiers[] = { 1,3,6,1,2,1,7,5,1,1};
    10.     AsnInteger              errorStatus, errorIndex;
    11.     TCPINFO                 *currentEntry, *newEntry;
    12.     UINT                    currentIndex;
    13.     WORD                    wVersionRequested;
    14.     WSADATA                 wsaData;
    15.     char                    localname[HOSTNAMELEN], remotename[HOSTNAMELEN];
    16.     char                    remoteport[PORTNAMELEN], localport[PORTNAMELEN];
    17.     char                    localaddr[ADDRESSLEN], remoteaddr[ADDRESSLEN];
    18.  
    19.     //
    20.     // Initialize winsock
    21.     //
    22.     wVersionRequested = MAKEWORD( 1, 1 );
    23.     if( WSAStartup(  wVersionRequested, &wsaData ) ) {
    24.         return 1;
    25.     }
    26.  
    27.     //
    28.     // Locate and initialize INETMIB1
    29.     //
    30.     if( !LoadInetMibEntryPoints()) {
    31.  
    32.         return 1;
    33.     }
    34.  
    35.     if( !SnmpExtensionInit( GetCurrentTime(), &hTrapEvent, &hIdentifier )) {
    36.         return 1;
    37.     }
    38.  
    39.     //
    40.     // Initialize the query structure once
    41.     //
    42.     bindEntry.name.idLength = 0xA;
    43.     bindEntry.name.ids = tcpidentifiers;
    44.     bindList.list = &bindEntry;
    45.     bindList.len  = 1;
    46.  
    47.     TcpInfoTable.prev = &TcpInfoTable;
    48.     TcpInfoTable.next = &TcpInfoTable;
    49.  
    50.     //
    51.     // Roll through TCP connections
    52.     //
    53.     currentIndex = 1;
    54.     currentEntry = &TcpInfoTable;
    55.     while(1) {
    56.  
    57.         if( !SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
    58.             &bindList, &errorStatus, &errorIndex )) {
    59.  
    60.             return 1;
    61.         }
    62.  
    63.         //
    64.         // Terminate when we're no longer seeing TCP information
    65.         //
    66.         if( bindEntry.name.idLength < 0xA ) break;
    67.  
    68.         //
    69.         // Go back to start of table if we're reading info
    70.         // about the next byte
    71.         //
    72.         if( currentIndex != bindEntry.name.ids[9] ) {
    73.  
    74.             currentEntry = TcpInfoTable.next;
    75.             currentIndex = bindEntry.name.ids[9];
    76.         }
    77.  
    78.         //
    79.         // Build our TCP information table
    80.         //
    81.         switch( bindEntry.name.ids[9] ) {
    82.  
    83.         case 1:
    84.            
    85.             //
    86.             // Always allocate a new structure
    87.             //
    88.             newEntry = (TCPINFO *) malloc( sizeof(TCPINFO ));
    89.             newEntry->prev = currentEntry;
    90.             newEntry->next = &TcpInfoTable;
    91.             currentEntry->next = newEntry;
    92.             currentEntry = newEntry;
    93.  
    94.             currentEntry->state = bindEntry.value.asnValue.number;
    95.             break;
    96.  
    97.         case 2:
    98.  
    99.             currentEntry->localip =
    100.                 *(UINT *) bindEntry.value.asnValue.address.stream;
    101.             currentEntry = currentEntry->next;
    102.             break;
    103.  
    104.         case 3:
    105.            
    106.             currentEntry->localport =
    107.                 bindEntry.value.asnValue.number;
    108.             currentEntry = currentEntry->next;
    109.             break;
    110.  
    111.         case 4:
    112.  
    113.             currentEntry->remoteip =
    114.                 *(UINT *) bindEntry.value.asnValue.address.stream;
    115.             currentEntry = currentEntry->next;
    116.             break;
    117.  
    118.         case 5:
    119.  
    120.             currentEntry->remoteport =
    121.                 bindEntry.value.asnValue.number;
    122.             currentEntry = currentEntry->next;
    123.             break;
    124.         }
    125.  
    126.     }
    127.    
    128.     //
    129.     // Now print the connection information
    130.     //
    131.     sprintf(acBuf, "%7s %-30s %-30s %s\n", "Proto", "Local", "Remote", "State" );
    132.  
    133.     lstOutput.AddTail ( new CString ( acBuf));
    134.  
    135.     currentEntry = TcpInfoTable.next;
    136.     while( currentEntry != &TcpInfoTable ) {
    137.  
    138.         sprintf( localaddr, "%s:%s",
    139.             GetIpHostName( TRUE, currentEntry->localip, localname, HOSTNAMELEN),
    140.             GetPortName( currentEntry->localport, "tcp", localport, PORTNAMELEN ));
    141.  
    142.         sprintf( remoteaddr, "%s:%s",
    143.             GetIpHostName( FALSE, currentEntry->remoteip, remotename, HOSTNAMELEN),
    144.             currentEntry->remoteip ?
    145.                 GetPortName( currentEntry->remoteport, "tcp", remoteport, PORTNAMELEN ):
    146.                 "0" );
    147.  
    148.         sprintf(acBuf,"%7s %-30s %-30s %s\n", "TCP",
    149.             localaddr, remoteaddr,
    150.             TcpState[currentEntry->state]);
    151.  
    152.         lstOutput.AddTail ( new CString ( acBuf));
    153.        
    154.         currentEntry = currentEntry->next;
    155.     }
    156.  
    157.     //
    158.     // Initialize the query structure once
    159.     //
    160.     bindEntry.name.idLength = 0xA;
    161.     bindEntry.name.ids = udpidentifiers;
    162.     bindList.list = &bindEntry;
    163.     bindList.len  = 1;
    164.  
    165.     UdpInfoTable.prev = &UdpInfoTable;
    166.     UdpInfoTable.next = &UdpInfoTable;
    167.  
    168.     //
    169.     // Roll through UDP endpoints
    170.     //
    171.     currentIndex = 1;
    172.     currentEntry = &UdpInfoTable;
    173.     while(1) {
    174.  
    175.         if( !SnmpExtensionQuery( ASN_RFC1157_GETNEXTREQUEST,
    176.             &bindList, &errorStatus, &errorIndex )) {
    177.  
    178.             return 1;
    179.         }
    180.  
    181.         //
    182.         // Terminate when we're no longer seeing TCP information
    183.         //
    184.         if( bindEntry.name.idLength < 0xA ) break;
    185.  
    186.         //
    187.         // Go back to start of table if we're reading info
    188.         // about the next byte
    189.         //
    190.         if( currentIndex != bindEntry.name.ids[9] ) {
    191.  
    192.             currentEntry = UdpInfoTable.next;
    193.             currentIndex = bindEntry.name.ids[9];
    194.         }
    195.  
    196.         //
    197.         // Build our TCP information table
    198.         //
    199.         switch( bindEntry.name.ids[9] ) {
    200.  
    201.         case 1:
    202.            
    203.             //
    204.             // Always allocate a new structure
    205.             //
    206.             newEntry = (TCPINFO *) malloc( sizeof(TCPINFO ));
    207.             newEntry->prev = currentEntry;
    208.             newEntry->next = &UdpInfoTable;
    209.             currentEntry->next = newEntry;
    210.             currentEntry = newEntry;
    211.  
    212.             currentEntry->localip =
    213.                 *(UINT *) bindEntry.value.asnValue.address.stream;
    214.             break;
    215.  
    216.         case 2:
    217.            
    218.             currentEntry->localport =
    219.                 bindEntry.value.asnValue.number;
    220.             currentEntry = currentEntry->next;
    221.             break;
    222.         }
    223.     }
    224.    
    225.     //
    226.     // Now print the connection information
    227.     //
    228.     currentEntry = UdpInfoTable.next;
    229.     while( currentEntry != &UdpInfoTable ) {
    230.  
    231.         sprintf(acBuf, "%7s %s:%s\n", "UDP",
    232.                 GetIpHostName( TRUE, currentEntry->localip, localname, HOSTNAMELEN),
    233.                 GetPortName( currentEntry->localport, "udp", localport, PORTNAMELEN ) );
    234.        
    235.         lstOutput.AddTail ( new CString ( acBuf));
    236.  
    237.         currentEntry = currentEntry->next;
    238.     }
    239. }
     
  6. slow

    slow New Member

    Публикаций:
    0
    Регистрация:
    27 дек 2004
    Сообщения:
    615
    наоборот же вроде :)