<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3523049</guid>
        <pubDate>Mon, 08 Sep 2014 10:31:55 +0000</pubDate>
        <title>Как средствами Delphi узнать имя процесса занявшее 80 порт.</title>
        <link>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3523049</link>
        <description><![CDATA[Emmys: ура, спасибо за подсказку, получилось.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unit Unit1;</div><div class="code_line">&nbsp;</div><div class="code_line">interface</div><div class="code_line">&nbsp;</div><div class="code_line">uses</div><div class="code_line">&nbsp;&nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,</div><div class="code_line">&nbsp;&nbsp;Dialogs, StdCtrls,winsock, IdContext, IdBaseComponent, IdComponent,</div><div class="code_line">&nbsp;&nbsp;IdCustomTCPServer, IdTCPServer, Sockets, ScktComp;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;TForm1 = class(TForm)</div><div class="code_line">&nbsp;&nbsp; &nbsp;Memo1: TMemo;</div><div class="code_line">&nbsp;&nbsp; &nbsp;ServerSocket1: TServerSocket;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure FormCreate(Sender: TObject);</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Private declarations }</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Public declarations }</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_CLOSED = 1; //The TCP connection is in the CLOSED state that represents no connection state at all.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_LISTEN = 2; //The TCP connection is in the LISTEN state waiting for a connection request from any remote TCP and port.</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_FIN_WAIT2 = 7; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP.</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_CLOSING = 9; //The TCP connection is in the CLOSING state waiting for a connection termination request acknowledgment from the remote TCP.</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_DELETE_TCB = 12;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;PTCP_TABLE_CLASS = ^TCP_TABLE_CLASS;</div><div class="code_line">&nbsp;&nbsp;TCP_TABLE_CLASS =</div><div class="code_line">&nbsp;&nbsp; &nbsp;(TCP_TABLE_BASIC_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_BASIC_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_BASIC_ALL,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_ALL,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_ALL);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;PMIB_TCPROW = ^_MIB_TCPROW;</div><div class="code_line">&nbsp;&nbsp;_MIB_TCPROW = record</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwState: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwLocalAddr: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwLocalPort: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwRemoteAddr: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwRemotePort: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwOwningPid: &nbsp;DWORD;</div><div class="code_line">&nbsp;&nbsp; end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;PMIB_TCPTABLE = ^_MIB_TCPTABLE;</div><div class="code_line">&nbsp;&nbsp;_MIB_TCPTABLE = record</div><div class="code_line">&nbsp;&nbsp; &nbsp;dwNumEntries: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Table: array[0..0] of _MIB_TCPROW;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;PVOID = Pointer;</div><div class="code_line">&nbsp;</div><div class="code_line">function GetExtendedTcpTable(pTcpTable: PVOID; pdwSize: PDWORD;</div><div class="code_line">&nbsp;&nbsp;bOrder: BOOL; ulAf: ULONG; TableClass: TCP_TABLE_CLASS;</div><div class="code_line">&nbsp;&nbsp;Reserved: ULONG): DWORD; stdcall; external &#39;Iphlpapi.dll&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Form1: TForm1;</div><div class="code_line">&nbsp;</div><div class="code_line">implementation</div><div class="code_line">&nbsp;</div><div class="code_line">{$R *.dfm}</div><div class="code_line">&nbsp;</div><div class="code_line">function StateToStateStr(State: DWORD): string;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := &#39;&#39;;</div><div class="code_line">&nbsp;&nbsp;case State of</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_CLOSED: Result := &#39;MIB_TCP_STATE_CLOSED&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_LISTEN: Result := &#39;MIB_TCP_STATE_LISTEN&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_SYN_SENT: Result := &#39;MIB_TCP_STATE_SYN_SENT&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_SYN_RCVD: Result := &#39;MIB_TCP_STATE_SYN_RCVD&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_ESTAB: Result := &#39;MIB_TCP_STATE_ESTAB&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_FIN_WAIT1: Result := &#39;MIB_TCP_STATE_FIN_WAIT1&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_FIN_WAIT2: Result := &#39;MIB_TCP_STATE_FIN_WAIT2&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_CLOSE_WAIT: Result := &#39;MIB_TCP_STATE_CLOSE_WAIT&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_CLOSING: Result := &#39;MIB_TCP_STATE_CLOSING&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_LAST_ACK: Result := &#39;MIB_TCP_STATE_LAST_ACK&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_TIME_WAIT: Result := &#39;MIB_TCP_STATE_TIME_WAIT&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_DELETE_TCB: Result := &#39;MIB_TCP_STATE_DELETE_TCB&#39;;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.FormCreate(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;pTcpTable: PMIB_TCPTABLE;</div><div class="code_line">&nbsp;&nbsp;MIB_TCPROW: _MIB_TCPROW;</div><div class="code_line">&nbsp;&nbsp;dwSize: DWORD;</div><div class="code_line">&nbsp;&nbsp;Res: DWORD;</div><div class="code_line">&nbsp;&nbsp;i: Integer;</div><div class="code_line">&nbsp;&nbsp;AF_INET:Cardinal;</div><div class="code_line">&nbsp;&nbsp;var</div><div class="code_line">&nbsp;&nbsp; &nbsp; ProcessID, ThreadID: Cardinal;</div><div class="code_line">begin</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;///Program Files/Borland/Delphi7/Bin/dclsockets70.bpl</div><div class="code_line">&nbsp;&nbsp; ProcessID:=0;</div><div class="code_line">&nbsp;&nbsp; ThreadID := GetWindowThreadProcessId(Application.Handle, ProcessID);</div><div class="code_line">&nbsp;</div><div class="code_line">form1.Memo1.Lines.Add (inttostR(ProcessID));</div><div class="code_line">form1.Memo1.Lines.Add (&#39;&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">{</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_CLOSED = 1; //The TCP connection is in the CLOSED state that represents no connection state at all.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_LISTEN = 2; //The TCP connection is in the LISTEN state waiting for a connection request from any remote TCP and port.</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_FIN_WAIT2 = 7; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP.</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_CLOSING = 9; //The TCP connection is in the CLOSING state waiting for a connection termination request acknowledgment from the remote TCP.</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_DELETE_TCB = 12;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;PTCP_TABLE_CLASS = ^TCP_TABLE_CLASS;</div><div class="code_line">&nbsp;&nbsp;TCP_TABLE_CLASS =</div><div class="code_line">&nbsp;&nbsp; &nbsp;(TCP_TABLE_BASIC_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_BASIC_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_BASIC_ALL,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_ALL,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_ALL);</div><div class="code_line">&nbsp;</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">// &nbsp;pTcpTable := nil;</div><div class="code_line">&nbsp;&nbsp;dwSize := 0;</div><div class="code_line">&nbsp;&nbsp;AF_INET:=0;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;Res := GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TCP_TABLE_OWNER_PID_LISTENER, 0);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if Res = ERROR_INVALID_PARAMETER then</div><div class="code_line">&nbsp;&nbsp; &nbsp;raise Exception.Create(&#39;ERROR_INVALID_PARAMETER&#39;);</div><div class="code_line">&nbsp;&nbsp;if Res = ERROR_INSUFFICIENT_BUFFER then</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;pTcpTable := GetMemory(dwSize);</div><div class="code_line">&nbsp;&nbsp; &nbsp;ZeroMemory(pTcpTable, dwSize);</div><div class="code_line">&nbsp;&nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TCP_TABLE_OWNER_PID_LISTENER, 0) = NO_ERROR then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for i := 0 to pTcpTable^.dwNumEntries - 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MIB_TCPROW := pTcpTable^.Table[i];</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;form1.Memo1.Lines.Add(StateToStateStr(MIB_TCPROW.dwState) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; State = &#39; + IntToStr(MIB_TCPROW.dwState) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; LocalAddr = &#39; &nbsp;+ inet_ntoa(in_addr(MIB_TCPROW.dwLocalAddr)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; LocalPort = &#39; &nbsp;+ IntToStr(ntohs(MIB_TCPROW.dwLocalPort)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; RemoteAddr = &#39; + inet_ntoa(in_addr(MIB_TCPROW.dwRemoteAddr)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; RemotePort = &#39; + IntToStr(ntohs(MIB_TCPROW.dwRemotePort)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; OwningPid = &#39; + IntToStr(MIB_TCPROW.dwOwningPid)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;FreeMemory(pTcpTable);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">end.</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>]]></description>
        <author>Emmys</author>
        <category>Delphi: Сетевое программирование</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3523023</guid>
        <pubDate>Mon, 08 Sep 2014 10:09:32 +0000</pubDate>
        <title>Как средствами Delphi узнать имя процесса занявшее 80 порт.</title>
        <link>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3523023</link>
        <description><![CDATA[jack128: Хм, вообще удивительно, что ты какой то валидный ответ от функции получаешь. Ты ведь ей передаешь TCP_TABLE_OWNER_PID_CONNECTIONS, значит получаешь ты таблицу вот <a class='tag-url' href='http://msdn.microsoft.com/en-us/library/aa366913.aspx' target='_blank'>этих</a> структур.]]></description>
        <author>jack128</author>
        <category>Delphi: Сетевое программирование</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3522935</guid>
        <pubDate>Mon, 08 Sep 2014 08:34:47 +0000</pubDate>
        <title>Как средствами Delphi узнать имя процесса занявшее 80 порт.</title>
        <link>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3522935</link>
        <description><![CDATA[Emmys: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unit Unit1;</div><div class="code_line">&nbsp;</div><div class="code_line">interface</div><div class="code_line">&nbsp;</div><div class="code_line">uses</div><div class="code_line">&nbsp;&nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,</div><div class="code_line">&nbsp;&nbsp;Dialogs, StdCtrls,winsock, IdContext, IdBaseComponent, IdComponent,</div><div class="code_line">&nbsp;&nbsp;IdCustomTCPServer, IdTCPServer, Sockets, ScktComp;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;TForm1 = class(TForm)</div><div class="code_line">&nbsp;&nbsp; &nbsp;Memo1: TMemo;</div><div class="code_line">&nbsp;&nbsp; &nbsp;ServerSocket1: TServerSocket;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure FormCreate(Sender: TObject);</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Private declarations }</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Public declarations }</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_CLOSED = 1; //The TCP connection is in the CLOSED state that represents no connection state at all.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_LISTEN = 2; //The TCP connection is in the LISTEN state waiting for a connection request from any remote TCP and port.</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_FIN_WAIT2 = 7; //The TCP connection is FIN-WAIT-1 state waiting for a connection termination request from the remote TCP.</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_CLOSING = 9; //The TCP connection is in the CLOSING state waiting for a connection termination request acknowledgment from the remote TCP.</div><div class="code_line">&nbsp;&nbsp;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).</div><div class="code_line">&nbsp;&nbsp;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.</div><div class="code_line">&nbsp;&nbsp;MIB_TCP_STATE_DELETE_TCB = 12;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;PTCP_TABLE_CLASS = ^TCP_TABLE_CLASS;</div><div class="code_line">&nbsp;&nbsp;TCP_TABLE_CLASS =</div><div class="code_line">&nbsp;&nbsp; &nbsp;(TCP_TABLE_BASIC_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_BASIC_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_BASIC_ALL,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_PID_ALL,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_LISTENER,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_CONNECTIONS,</div><div class="code_line">&nbsp;&nbsp; &nbsp;TCP_TABLE_OWNER_MODULE_ALL);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;PMIB_TCPROW = ^_MIB_TCPROW;</div><div class="code_line">&nbsp;&nbsp;_MIB_TCPROW = record</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwState: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwLocalAddr: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwLocalPort: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwRemoteAddr: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp; dwRemotePort: DWORD;</div><div class="code_line">&nbsp;&nbsp; end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;PMIB_TCPTABLE = ^_MIB_TCPTABLE;</div><div class="code_line">&nbsp;&nbsp;_MIB_TCPTABLE = record</div><div class="code_line">&nbsp;&nbsp; &nbsp;dwNumEntries: DWORD;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Table: array[0..0] of _MIB_TCPROW;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;PVOID = Pointer;</div><div class="code_line">&nbsp;</div><div class="code_line">function GetExtendedTcpTable(pTcpTable: PVOID; pdwSize: PDWORD;</div><div class="code_line">&nbsp;&nbsp;bOrder: BOOL; ulAf: ULONG; TableClass: TCP_TABLE_CLASS;</div><div class="code_line">&nbsp;&nbsp;Reserved: ULONG): DWORD; stdcall; external &#39;Iphlpapi.dll&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Form1: TForm1;</div><div class="code_line">&nbsp;</div><div class="code_line">implementation</div><div class="code_line">&nbsp;</div><div class="code_line">{$R *.dfm}</div><div class="code_line">&nbsp;</div><div class="code_line">function StateToStateStr(State: DWORD): string;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := &#39;&#39;;</div><div class="code_line">&nbsp;&nbsp;case State of</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_CLOSED: Result := &#39;MIB_TCP_STATE_CLOSED&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_LISTEN: Result := &#39;MIB_TCP_STATE_LISTEN&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_SYN_SENT: Result := &#39;MIB_TCP_STATE_SYN_SENT&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_SYN_RCVD: Result := &#39;MIB_TCP_STATE_SYN_RCVD&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_ESTAB: Result := &#39;MIB_TCP_STATE_ESTAB&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_FIN_WAIT1: Result := &#39;MIB_TCP_STATE_FIN_WAIT1&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_FIN_WAIT2: Result := &#39;MIB_TCP_STATE_FIN_WAIT2&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_CLOSE_WAIT: Result := &#39;MIB_TCP_STATE_CLOSE_WAIT&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_CLOSING: Result := &#39;MIB_TCP_STATE_CLOSING&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_LAST_ACK: Result := &#39;MIB_TCP_STATE_LAST_ACK&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_TIME_WAIT: Result := &#39;MIB_TCP_STATE_TIME_WAIT&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;MIB_TCP_STATE_DELETE_TCB: Result := &#39;MIB_TCP_STATE_DELETE_TCB&#39;;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.FormCreate(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;pTcpTable: PMIB_TCPTABLE;</div><div class="code_line">&nbsp;&nbsp;MIB_TCPROW: _MIB_TCPROW;</div><div class="code_line">&nbsp;&nbsp;dwSize: DWORD;</div><div class="code_line">&nbsp;&nbsp;Res: DWORD;</div><div class="code_line">&nbsp;&nbsp;i: Integer;</div><div class="code_line">&nbsp;&nbsp;AF_INET:Cardinal;</div><div class="code_line">&nbsp;&nbsp;var</div><div class="code_line">&nbsp;&nbsp; &nbsp; ProcessID, ThreadID: Cardinal;</div><div class="code_line">begin</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;///Program Files/Borland/Delphi7/Bin/dclsockets70.bpl</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; ThreadID := GetWindowThreadProcessId(Application.Handle, ProcessID);</div><div class="code_line">&nbsp;</div><div class="code_line">form1.Memo1.Lines.Add (inttostR(ThreadID));</div><div class="code_line">form1.Memo1.Lines.Add (&#39;&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;pTcpTable := nil;</div><div class="code_line">&nbsp;&nbsp;dwSize := 0;</div><div class="code_line">&nbsp;&nbsp;AF_INET:=0;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;Res := GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TCP_TABLE_OWNER_PID_CONNECTIONS, 0);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;if Res = ERROR_INVALID_PARAMETER then</div><div class="code_line">&nbsp;&nbsp; &nbsp;raise Exception.Create(&#39;ERROR_INVALID_PARAMETER&#39;);</div><div class="code_line">&nbsp;&nbsp;if Res = ERROR_INSUFFICIENT_BUFFER then</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;pTcpTable := GetMemory(dwSize);</div><div class="code_line">&nbsp;&nbsp; &nbsp;ZeroMemory(pTcpTable, dwSize);</div><div class="code_line">&nbsp;&nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if GetExtendedTcpTable(pTcpTable, @dwSize, False, MIB_TCP_STATE_LISTEN,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;TCP_TABLE_OWNER_PID_CONNECTIONS, 0) = NO_ERROR then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for i := 0 to pTcpTable^.dwNumEntries - 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MIB_TCPROW := pTcpTable^.Table[i];</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;form1.Memo1.Lines.Add(StateToStateStr(MIB_TCPROW.dwState) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; State = &#39; + IntToStr(MIB_TCPROW.dwState) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; LocalAddr = &#39; &nbsp;+ inet_ntoa(in_addr(MIB_TCPROW.dwLocalAddr)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; LocalPort = &#39; &nbsp;+ IntToStr(ntohs(MIB_TCPROW.dwLocalPort)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; RemoteAddr = &#39; + inet_ntoa(in_addr(MIB_TCPROW.dwRemoteAddr)) +</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39; RemotePort = &#39; + IntToStr(ntohs(MIB_TCPROW.dwRemotePort))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;FreeMemory(pTcpTable);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">end.</div></ol></div></div></div></div> <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2014-09-08T08:36:41+00:00">08.09.14, 08:36</time></span></span><br>
я понимаю как то по PID мне надо найти по списку. но что то не так делаю.<br>
в самом приложении открываю TCP порт 77777<br>
<br>
помогите добить<br>
<br>
получаю:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">Memo1</div><div class="code_line">9300</div><div class="code_line">&nbsp;</div><div class="code_line">MIB_TCP_STATE_ESTAB State = 5 LocalAddr = 10.41.64.131 LocalPort = 445 RemoteAddr = 10.41.64.21 RemotePort = 1331</div><div class="code_line">MIB_TCP_STATE_SYN_RCVD State = 4 LocalAddr = 5.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512</div><div class="code_line">&nbsp;State = 37828 LocalAddr = 212.5.0.0 LocalPort = 1280 RemoteAddr = 127.0.0.1 RemotePort = 1110</div><div class="code_line">&nbsp;State = 16777343 LocalAddr = 196.154.0.0 LocalPort = 54277 RemoteAddr = 5.0.0.0 RemotePort = 32512</div><div class="code_line">&nbsp;State = 22020 LocalAddr = 127.0.0.1 LocalPort = 50338 RemoteAddr = 212.5.0.0 RemotePort = 1280</div><div class="code_line">&nbsp;State = 16777343 LocalAddr = 4.86.0.0 LocalPort = 32512 RemoteAddr = 196.164.0.0 RemotePort = 54277</div><div class="code_line">MIB_TCP_STATE_TIME_WAIT State = 11 LocalAddr = 127.0.0.1 LocalPort = 1110 RemoteAddr = 127.0.0.1 RemotePort = 53743</div><div class="code_line">&nbsp;State = 0 LocalAddr = 11.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512</div><div class="code_line">&nbsp;State = 33490 LocalAddr = 0.0.0.0 LocalPort = 2816 RemoteAddr = 127.0.0.1 RemotePort = 1110</div><div class="code_line">&nbsp;State = 16777343 LocalAddr = 210.153.0.0 LocalPort = 0 RemoteAddr = 5.0.0.0 RemotePort = 32512</div><div class="code_line">&nbsp;State = 22020 LocalAddr = 127.0.0.1 LocalPort = 53915 RemoteAddr = 212.5.0.0 RemotePort = 2816</div><div class="code_line">&nbsp;State = 16777343 LocalAddr = 4.86.0.0 LocalPort = 32512 RemoteAddr = 210.181.0.0 RemotePort = 0</div><div class="code_line">MIB_TCP_STATE_TIME_WAIT State = 11 LocalAddr = 127.0.0.1 LocalPort = 1110 RemoteAddr = 127.0.0.1 RemotePort = 53945</div><div class="code_line">&nbsp;State = 0 LocalAddr = 11.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512</div><div class="code_line">&nbsp;State = 48082 LocalAddr = 0.0.0.0 LocalPort = 2816 RemoteAddr = 127.0.0.1 RemotePort = 1110</div><div class="code_line">&nbsp;State = 16777343 LocalAddr = 210.189.0.0 LocalPort = 0 RemoteAddr = 5.0.0.0 RemotePort = 32512</div><div class="code_line">&nbsp;State = 22020 LocalAddr = 127.0.0.1 LocalPort = 53963 RemoteAddr = 212.5.0.0 RemotePort = 1280</div><div class="code_line">&nbsp;State = 16777343 LocalAddr = 4.86.0.0 LocalPort = 32512 RemoteAddr = 210.208.0.0 RemotePort = 54277</div><div class="code_line">MIB_TCP_STATE_TIME_WAIT State = 11 LocalAddr = 127.0.0.1 LocalPort = 1110 RemoteAddr = 127.0.0.1 RemotePort = 53977</div><div class="code_line">&nbsp;State = 0 LocalAddr = 5.0.0.0 LocalPort = 32512 RemoteAddr = 4.86.0.0 RemotePort = 32512</div></ol></div></div></div></div>]]></description>
        <author>Emmys</author>
        <category>Delphi: Сетевое программирование</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3522850</guid>
        <pubDate>Mon, 08 Sep 2014 06:37:48 +0000</pubDate>
        <title>Как средствами Delphi узнать имя процесса занявшее 80 порт.</title>
        <link>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3522850</link>
        <description><![CDATA[jack128: <a class='tag-url' href='http://msdn.microsoft.com/en-us/library/aa365928.aspx?ppud=4' target='_blank'>http://msdn.microsoft.com/en-us/library/aa365928.aspx?ppud=4</a>]]></description>
        <author>jack128</author>
        <category>Delphi: Сетевое программирование</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3522759</guid>
        <pubDate>Sun, 07 Sep 2014 17:48:16 +0000</pubDate>
        <title>Как средствами Delphi узнать имя процесса занявшее 80 порт.</title>
        <link>https://forum.sources.ru/index.php?showtopic=394132&amp;view=findpost&amp;p=3522759</link>
        <description><![CDATA[Emmys: Как средствами Delphi узнать имя процесса занявшее 80 порт? приложение пишу под Windows 7 и выше (разрядность любая). спасибо]]></description>
        <author>Emmys</author>
        <category>Delphi: Сетевое программирование</category>
      </item>
	
      </channel>
      </rss>
	