На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
! Соблюдайте общие правила форума
Пожалуйста, выделяйте текст программы тегом [сode=pas] ... [/сode]. Для этого используйте кнопку [code=pas] в форме ответа или комбобокс, если нужно вставить код на языке, отличном от Дельфи/Паскаля.
Указывайте точные версии Delphi и используемых сетевых библиотек.

Не приветствуется поднятие старых тем. Если ваш вопрос перекликается со старой темой, то для вопроса лучше создать новую тему, а старую указать в первом сообщении с описанием взаимосвязи.

Внимание:
попытки открытия обсуждений реализации вредоносного ПО, включая различные интерпретации спам-ботов, наказывается предупреждением на 30 дней.
Повторная попытка - 60 дней. Последующие попытки бан.
Мат в разделе - бан на три месяца...

Полезные ссылки:
user posted image MSDN Library user posted image FAQ раздела user posted image Поиск по разделу user posted image Как правильно задавать вопросы


Выразить свое отношение к модераторам раздела можно здесь: user posted image Krid, user posted image Rouse_

Модераторы: Krid, Rouse_
  
> Как средствами Delphi узнать имя процесса занявшее 80 порт.
    Как средствами Delphi узнать имя процесса занявшее 80 порт? приложение пишу под Windows 7 и выше (разрядность любая). спасибо
        ExpandedWrap disabled
          unit Unit1;
           
          interface
           
          uses
            Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
            Dialogs, StdCtrls,winsock, IdContext, IdBaseComponent, IdComponent,
            IdCustomTCPServer, IdTCPServer, Sockets, ScktComp;
           
          type
            TForm1 = class(TForm)
              Memo1: TMemo;
              ServerSocket1: TServerSocket;
              procedure FormCreate(Sender: TObject);
            private
              { Private declarations }
            public
              { Public declarations }
            end;
           
           
           
           
           
           
           
           
           
           
           
           
           
          const
            MIB_TCP_STATE_CLOSED = 1; //The TCP connection is in the CLOSED state that represents no connection state at all.
            MIB_TCP_STATE_LISTEN = 2; //The TCP connection is in the LISTEN state waiting for a connection request from any remote TCP and port.
            MIB_TCP_STATE_SYN_SENT = 3; //The TCP connection is in the SYN-SENT state waiting for a matching connection request after having sent a connection request (SYN packet).
            MIB_TCP_STATE_SYN_RCVD = 4; //The TCP connection is in the SYN-RECEIVED state waiting for a confirming connection request acknowledgment after having both received and sent a connection request (SYN packet).
            MIB_TCP_STATE_ESTAB = 5; //The TCP connection is in the ESTABLISHED state that represents an open connection, data received can be delivered to the user. This is the normal state for the data transfer phase of the TCP connection.
            MIB_TCP_STATE_FIN_WAIT1 = 6; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.
            MIB_TCP_STATE_FIN_WAIT2 = 7; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP.
            MIB_TCP_STATE_CLOSE_WAIT = 8; //The TCP connection is in the CLOSE-WAIT state waiting for a connection termination request from the local user.
            MIB_TCP_STATE_CLOSING = 9; //The TCP connection is in the CLOSING state waiting for a connection termination request acknowledgment from the remote TCP.
            MIB_TCP_STATE_LAST_ACK = 10; //The TCP connection is in the LAST-ACK state waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
            MIB_TCP_STATE_TIME_WAIT = 11; //The TCP connection is in the TIME-WAIT state waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.
            MIB_TCP_STATE_DELETE_TCB = 12;
           
          type
            PTCP_TABLE_CLASS = ^TCP_TABLE_CLASS;
            TCP_TABLE_CLASS =
              (TCP_TABLE_BASIC_LISTENER,
              TCP_TABLE_BASIC_CONNECTIONS,
              TCP_TABLE_BASIC_ALL,
              TCP_TABLE_OWNER_PID_LISTENER,
              TCP_TABLE_OWNER_PID_CONNECTIONS,
              TCP_TABLE_OWNER_PID_ALL,
              TCP_TABLE_OWNER_MODULE_LISTENER,
              TCP_TABLE_OWNER_MODULE_CONNECTIONS,
              TCP_TABLE_OWNER_MODULE_ALL);
           
            PMIB_TCPROW = ^_MIB_TCPROW;
            _MIB_TCPROW = record
               dwState: DWORD;
               dwLocalAddr: DWORD;
               dwLocalPort: DWORD;
               dwRemoteAddr: DWORD;
               dwRemotePort: DWORD;
             end;
           
            PMIB_TCPTABLE = ^_MIB_TCPTABLE;
            _MIB_TCPTABLE = record
              dwNumEntries: DWORD;
              Table: array[0..0] of _MIB_TCPROW;
            end;
           
           
          type
            PVOID = Pointer;
           
          function GetExtendedTcpTable(pTcpTable: PVOID; pdwSize: PDWORD;
            bOrder: BOOL; ulAf: ULONG; TableClass: TCP_TABLE_CLASS;
            Reserved: ULONG): DWORD; stdcall; external 'Iphlpapi.dll';
           
          var
            Form1: TForm1;
           
          implementation
           
          {$R *.dfm}
           
          function StateToStateStr(State: DWORD): string;
          begin
            Result := '';
            case State of
              MIB_TCP_STATE_CLOSED: Result := 'MIB_TCP_STATE_CLOSED';
              MIB_TCP_STATE_LISTEN: Result := 'MIB_TCP_STATE_LISTEN';
              MIB_TCP_STATE_SYN_SENT: Result := 'MIB_TCP_STATE_SYN_SENT';
              MIB_TCP_STATE_SYN_RCVD: Result := 'MIB_TCP_STATE_SYN_RCVD';
              MIB_TCP_STATE_ESTAB: Result := 'MIB_TCP_STATE_ESTAB';
              MIB_TCP_STATE_FIN_WAIT1: Result := 'MIB_TCP_STATE_FIN_WAIT1';
              MIB_TCP_STATE_FIN_WAIT2: Result := 'MIB_TCP_STATE_FIN_WAIT2';
              MIB_TCP_STATE_CLOSE_WAIT: Result := 'MIB_TCP_STATE_CLOSE_WAIT';
              MIB_TCP_STATE_CLOSING: Result := 'MIB_TCP_STATE_CLOSING';
              MIB_TCP_STATE_LAST_ACK: Result := 'MIB_TCP_STATE_LAST_ACK';
              MIB_TCP_STATE_TIME_WAIT: Result := 'MIB_TCP_STATE_TIME_WAIT';
              MIB_TCP_STATE_DELETE_TCB: Result := 'MIB_TCP_STATE_DELETE_TCB';
            end;
          end;
           
           
          procedure TForm1.FormCreate(Sender: TObject);
          var
            pTcpTable: PMIB_TCPTABLE;
            MIB_TCPROW: _MIB_TCPROW;
            dwSize: DWORD;
            Res: DWORD;
            i: Integer;
            AF_INET:Cardinal;
            var
               ProcessID, ThreadID: Cardinal;
          begin
           
           ///Program Files/Borland/Delphi7/Bin/dclsockets70.bpl
           
             ThreadID := GetWindowThreadProcessId(Application.Handle, ProcessID);
           
          form1.Memo1.Lines.Add (inttostR(ThreadID));
          form1.Memo1.Lines.Add ('');
           
           
           
           
           
            pTcpTable := nil;
            dwSize := 0;
            AF_INET:=0;
           
            Res := GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,
                  TCP_TABLE_OWNER_PID_CONNECTIONS, 0);
           
            if Res = ERROR_INVALID_PARAMETER then
              raise Exception.Create('ERROR_INVALID_PARAMETER');
            if Res = ERROR_INSUFFICIENT_BUFFER then
            begin
              pTcpTable := GetMemory(dwSize);
              ZeroMemory(pTcpTable, dwSize);
              try
                if GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,
                  TCP_TABLE_OWNER_PID_CONNECTIONS, 0) = NO_ERROR then
                begin
                  for i := 0 to pTcpTable^.dwNumEntries - 1 do
                  begin
                    MIB_TCPROW := pTcpTable^.Table[i];
                    form1.Memo1.Lines.Add(StateToStateStr(MIB_TCPROW.dwState) +
                      ' State = ' + IntToStr(MIB_TCPROW.dwState) +
                      ' LocalAddr = '  + inet_ntoa(in_addr(MIB_TCPROW.dwLocalAddr)) +
                      ' LocalPort = '  + IntToStr(ntohs(MIB_TCPROW.dwLocalPort)) +
                      ' RemoteAddr = ' + inet_ntoa(in_addr(MIB_TCPROW.dwRemoteAddr)) +
                      ' RemotePort = ' + IntToStr(ntohs(MIB_TCPROW.dwRemotePort))
                      );
                  end;
           
           
                end;
              finally
                FreeMemory(pTcpTable);
              end
            end;
          end;
           
          end.


        Добавлено
        я понимаю как то по PID мне надо найти по списку. но что то не так делаю.
        в самом приложении открываю TCP порт 77777

        помогите добить

        получаю:

        ExpandedWrap disabled
          Memo1
          9300
           
          MIB_TCP_STATE_ESTAB State = 5 LocalAddr = 10.41.64.131 LocalPort = 445 RemoteAddr = 10.41.64.21 RemotePort = 1331
          MIB_TCP_STATE_SYN_RCVD State = 4 LocalAddr = 5.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512
           State = 37828 LocalAddr = 212.5.0.0 LocalPort = 1280 RemoteAddr = 127.0.0.1 RemotePort = 1110
           State = 16777343 LocalAddr = 196.154.0.0 LocalPort = 54277 RemoteAddr = 5.0.0.0 RemotePort = 32512
           State = 22020 LocalAddr = 127.0.0.1 LocalPort = 50338 RemoteAddr = 212.5.0.0 RemotePort = 1280
           State = 16777343 LocalAddr = 4.86.0.0 LocalPort = 32512 RemoteAddr = 196.164.0.0 RemotePort = 54277
          MIB_TCP_STATE_TIME_WAIT State = 11 LocalAddr = 127.0.0.1 LocalPort = 1110 RemoteAddr = 127.0.0.1 RemotePort = 53743
           State = 0 LocalAddr = 11.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512
           State = 33490 LocalAddr = 0.0.0.0 LocalPort = 2816 RemoteAddr = 127.0.0.1 RemotePort = 1110
           State = 16777343 LocalAddr = 210.153.0.0 LocalPort = 0 RemoteAddr = 5.0.0.0 RemotePort = 32512
           State = 22020 LocalAddr = 127.0.0.1 LocalPort = 53915 RemoteAddr = 212.5.0.0 RemotePort = 2816
           State = 16777343 LocalAddr = 4.86.0.0 LocalPort = 32512 RemoteAddr = 210.181.0.0 RemotePort = 0
          MIB_TCP_STATE_TIME_WAIT State = 11 LocalAddr = 127.0.0.1 LocalPort = 1110 RemoteAddr = 127.0.0.1 RemotePort = 53945
           State = 0 LocalAddr = 11.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512
           State = 48082 LocalAddr = 0.0.0.0 LocalPort = 2816 RemoteAddr = 127.0.0.1 RemotePort = 1110
           State = 16777343 LocalAddr = 210.189.0.0 LocalPort = 0 RemoteAddr = 5.0.0.0 RemotePort = 32512
           State = 22020 LocalAddr = 127.0.0.1 LocalPort = 53963 RemoteAddr = 212.5.0.0 RemotePort = 1280
           State = 16777343 LocalAddr = 4.86.0.0 LocalPort = 32512 RemoteAddr = 210.208.0.0 RemotePort = 54277
          MIB_TCP_STATE_TIME_WAIT State = 11 LocalAddr = 127.0.0.1 LocalPort = 1110 RemoteAddr = 127.0.0.1 RemotePort = 53977
           State = 0 LocalAddr = 5.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512
          Хм, вообще удивительно, что ты какой то валидный ответ от функции получаешь. Ты ведь ей передаешь TCP_TABLE_OWNER_PID_CONNECTIONS, значит получаешь ты таблицу вот этих структур.
            ура, спасибо за подсказку, получилось.
            ExpandedWrap disabled
              unit Unit1;
               
              interface
               
              uses
                Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
                Dialogs, StdCtrls,winsock, IdContext, IdBaseComponent, IdComponent,
                IdCustomTCPServer, IdTCPServer, Sockets, ScktComp;
               
              type
                TForm1 = class(TForm)
                  Memo1: TMemo;
                  ServerSocket1: TServerSocket;
                  procedure FormCreate(Sender: TObject);
                private
                  { Private declarations }
                public
                  { Public declarations }
                end;
               
               
               
               
               
               
               
               
               
               
               
               
               
              const
                MIB_TCP_STATE_CLOSED = 1; //The TCP connection is in the CLOSED state that represents no connection state at all.
                MIB_TCP_STATE_LISTEN = 2; //The TCP connection is in the LISTEN state waiting for a connection request from any remote TCP and port.
                MIB_TCP_STATE_SYN_SENT = 3; //The TCP connection is in the SYN-SENT state waiting for a matching connection request after having sent a connection request (SYN packet).
                MIB_TCP_STATE_SYN_RCVD = 4; //The TCP connection is in the SYN-RECEIVED state waiting for a confirming connection request acknowledgment after having both received and sent a connection request (SYN packet).
                MIB_TCP_STATE_ESTAB = 5; //The TCP connection is in the ESTABLISHED state that represents an open connection, data received can be delivered to the user. This is the normal state for the data transfer phase of the TCP connection.
                MIB_TCP_STATE_FIN_WAIT1 = 6; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.
                MIB_TCP_STATE_FIN_WAIT2 = 7; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP.
                MIB_TCP_STATE_CLOSE_WAIT = 8; //The TCP connection is in the CLOSE-WAIT state waiting for a connection termination request from the local user.
                MIB_TCP_STATE_CLOSING = 9; //The TCP connection is in the CLOSING state waiting for a connection termination request acknowledgment from the remote TCP.
                MIB_TCP_STATE_LAST_ACK = 10; //The TCP connection is in the LAST-ACK state waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
                MIB_TCP_STATE_TIME_WAIT = 11; //The TCP connection is in the TIME-WAIT state waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.
                MIB_TCP_STATE_DELETE_TCB = 12;
               
              type
                PTCP_TABLE_CLASS = ^TCP_TABLE_CLASS;
                TCP_TABLE_CLASS =
                  (TCP_TABLE_BASIC_LISTENER,
                  TCP_TABLE_BASIC_CONNECTIONS,
                  TCP_TABLE_BASIC_ALL,
                  TCP_TABLE_OWNER_PID_LISTENER,
                  TCP_TABLE_OWNER_PID_CONNECTIONS,
                  TCP_TABLE_OWNER_PID_ALL,
                  TCP_TABLE_OWNER_MODULE_LISTENER,
                  TCP_TABLE_OWNER_MODULE_CONNECTIONS,
                  TCP_TABLE_OWNER_MODULE_ALL);
               
                PMIB_TCPROW = ^_MIB_TCPROW;
                _MIB_TCPROW = record
                   dwState: DWORD;
                   dwLocalAddr: DWORD;
                   dwLocalPort: DWORD;
                   dwRemoteAddr: DWORD;
                   dwRemotePort: DWORD;
                   dwOwningPid:  DWORD;
                 end;
               
                PMIB_TCPTABLE = ^_MIB_TCPTABLE;
                _MIB_TCPTABLE = record
                  dwNumEntries: DWORD;
                  Table: array[0..0] of _MIB_TCPROW;
                end;
               
               
              type
                PVOID = Pointer;
               
              function GetExtendedTcpTable(pTcpTable: PVOID; pdwSize: PDWORD;
                bOrder: BOOL; ulAf: ULONG; TableClass: TCP_TABLE_CLASS;
                Reserved: ULONG): DWORD; stdcall; external 'Iphlpapi.dll';
               
              var
                Form1: TForm1;
               
              implementation
               
              {$R *.dfm}
               
              function StateToStateStr(State: DWORD): string;
              begin
                Result := '';
                case State of
                  MIB_TCP_STATE_CLOSED: Result := 'MIB_TCP_STATE_CLOSED';
                  MIB_TCP_STATE_LISTEN: Result := 'MIB_TCP_STATE_LISTEN';
                  MIB_TCP_STATE_SYN_SENT: Result := 'MIB_TCP_STATE_SYN_SENT';
                  MIB_TCP_STATE_SYN_RCVD: Result := 'MIB_TCP_STATE_SYN_RCVD';
                  MIB_TCP_STATE_ESTAB: Result := 'MIB_TCP_STATE_ESTAB';
                  MIB_TCP_STATE_FIN_WAIT1: Result := 'MIB_TCP_STATE_FIN_WAIT1';
                  MIB_TCP_STATE_FIN_WAIT2: Result := 'MIB_TCP_STATE_FIN_WAIT2';
                  MIB_TCP_STATE_CLOSE_WAIT: Result := 'MIB_TCP_STATE_CLOSE_WAIT';
                  MIB_TCP_STATE_CLOSING: Result := 'MIB_TCP_STATE_CLOSING';
                  MIB_TCP_STATE_LAST_ACK: Result := 'MIB_TCP_STATE_LAST_ACK';
                  MIB_TCP_STATE_TIME_WAIT: Result := 'MIB_TCP_STATE_TIME_WAIT';
                  MIB_TCP_STATE_DELETE_TCB: Result := 'MIB_TCP_STATE_DELETE_TCB';
                end;
              end;
               
               
              procedure TForm1.FormCreate(Sender: TObject);
              var
                pTcpTable: PMIB_TCPTABLE;
                MIB_TCPROW: _MIB_TCPROW;
                dwSize: DWORD;
                Res: DWORD;
                i: Integer;
                AF_INET:Cardinal;
                var
                   ProcessID, ThreadID: Cardinal;
              begin
               
               ///Program Files/Borland/Delphi7/Bin/dclsockets70.bpl
                 ProcessID:=0;
                 ThreadID := GetWindowThreadProcessId(Application.Handle, ProcessID);
               
              form1.Memo1.Lines.Add (inttostR(ProcessID));
              form1.Memo1.Lines.Add ('');
               
              {
               
                MIB_TCP_STATE_CLOSED = 1; //The TCP connection is in the CLOSED state that represents no connection state at all.
                MIB_TCP_STATE_LISTEN = 2; //The TCP connection is in the LISTEN state waiting for a connection request from any remote TCP and port.
                MIB_TCP_STATE_SYN_SENT = 3; //The TCP connection is in the SYN-SENT state waiting for a matching connection request after having sent a connection request (SYN packet).
                MIB_TCP_STATE_SYN_RCVD = 4; //The TCP connection is in the SYN-RECEIVED state waiting for a confirming connection request acknowledgment after having both received and sent a connection request (SYN packet).
                MIB_TCP_STATE_ESTAB = 5; //The TCP connection is in the ESTABLISHED state that represents an open connection, data received can be delivered to the user. This is the normal state for the data transfer phase of the TCP connection.
                MIB_TCP_STATE_FIN_WAIT1 = 6; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.
                MIB_TCP_STATE_FIN_WAIT2 = 7; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP.
                MIB_TCP_STATE_CLOSE_WAIT = 8; //The TCP connection is in the CLOSE-WAIT state waiting for a connection termination request from the local user.
                MIB_TCP_STATE_CLOSING = 9; //The TCP connection is in the CLOSING state waiting for a connection termination request acknowledgment from the remote TCP.
                MIB_TCP_STATE_LAST_ACK = 10; //The TCP connection is in the LAST-ACK state waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
                MIB_TCP_STATE_TIME_WAIT = 11; //The TCP connection is in the TIME-WAIT state waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request.
                MIB_TCP_STATE_DELETE_TCB = 12;
               
               
                  PTCP_TABLE_CLASS = ^TCP_TABLE_CLASS;
                TCP_TABLE_CLASS =
                  (TCP_TABLE_BASIC_LISTENER,
                  TCP_TABLE_BASIC_CONNECTIONS,
                  TCP_TABLE_BASIC_ALL,
                  TCP_TABLE_OWNER_PID_LISTENER,
                  TCP_TABLE_OWNER_PID_CONNECTIONS,
                  TCP_TABLE_OWNER_PID_ALL,
                  TCP_TABLE_OWNER_MODULE_LISTENER,
                  TCP_TABLE_OWNER_MODULE_CONNECTIONS,
                  TCP_TABLE_OWNER_MODULE_ALL);
               
              }
               
              //  pTcpTable := nil;
                dwSize := 0;
                AF_INET:=0;
               
                Res := GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,
                      TCP_TABLE_OWNER_PID_LISTENER, 0);
               
                if Res = ERROR_INVALID_PARAMETER then
                  raise Exception.Create('ERROR_INVALID_PARAMETER');
                if Res = ERROR_INSUFFICIENT_BUFFER then
                begin
                  pTcpTable := GetMemory(dwSize);
                  ZeroMemory(pTcpTable, dwSize);
                  try
                    if GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,
                      TCP_TABLE_OWNER_PID_LISTENER, 0) = NO_ERROR then
                    begin
                      for i := 0 to pTcpTable^.dwNumEntries - 1 do
                      begin
                        MIB_TCPROW := pTcpTable^.Table[i];
                        form1.Memo1.Lines.Add(StateToStateStr(MIB_TCPROW.dwState) +
                          ' State = ' + IntToStr(MIB_TCPROW.dwState) +
                          ' LocalAddr = '  + inet_ntoa(in_addr(MIB_TCPROW.dwLocalAddr)) +
                          ' LocalPort = '  + IntToStr(ntohs(MIB_TCPROW.dwLocalPort)) +
                          ' RemoteAddr = ' + inet_ntoa(in_addr(MIB_TCPROW.dwRemoteAddr)) +
                          ' RemotePort = ' + IntToStr(ntohs(MIB_TCPROW.dwRemotePort)) +
                          ' OwningPid = ' + IntToStr(MIB_TCPROW.dwOwningPid)
                          );
                      end;
               
               
                    end;
                  finally
                    FreeMemory(pTcpTable);
                  end
                end;
              end;
               
              end.
            0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
            0 пользователей:


            Рейтинг@Mail.ru
            [ Script execution time: 0.0702 ]   [ 16 queries used ]   [ Generated: 20.09.26, 18:02 GMT ]